-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightOj 1011.cpp
83 lines (61 loc) · 1.28 KB
/
LightOj 1011.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*Which of the favors of your Lord will you deny ?*/
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define PII pair<int,int>
#define LPII pair<LL, pair<int,int> >
#define MP make_pair
#define F first
#define S second
#define LINF LLONG_MAX
int n;
LL ara[16][16];
LL dp[16][1<<16];
//bool visited[30];
void init()
{
memset(ara,0,sizeof ara);
memset(dp,(LL)-1,sizeof dp);
//memset(visited,0,sizeof visited);
}
LL solve(int r,int mask)
{
if(r>=n)
return 0;
if(dp[r][mask]==-1)
{
for(int i=0; i<n; i++) // i means col
{
if(!(mask&(1<<i)))
dp[r][mask]=max(dp[r][mask],ara[r][i]+solve(r+1,mask | (1<<i)));
}
}
//else
return dp[r][mask];
}
int main()
{
//freopen("LightOj1011.txt","w",stdout);
int tc;
scanf("%d",&tc);
for(int q=1; q<=tc; q++)
{
init();
scanf("%d",&n);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
scanf("%lld",&ara[i][j]);
LL ans=solve(0,0);
// for(int i=0; i<n; i++)
// {
// for(int j=0; j<(1<<n); j++)
// printf("%lld ",dp[i][j]);
//
// printf("\n");
//
// }
//
printf("Case %d: %lld\n",q,ans);
}
return 0;
}