-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightOj-1011 - Marriage Ceremonies.cpp
73 lines (58 loc) · 1.32 KB
/
LightOj-1011 - Marriage Ceremonies.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
/*
UserId: imranRNKENT
Problem: Marriage Ceremonies
Language: C++
Main Idea: DP
*/
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define maxn 100010
#define ints size_t
#define pbk push_back
#define intl long long
#define mod 1000000007
#define pi 2 * acos(0.0)
#define sf(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define sl(n) scanf("%lld", &n)
#define sc(c) scanf(" %c", &c)
#define ss(str) scanf("%s", str)
#define pc(c) printf("%c\n", c)
#define pf(n) printf("%d\n", n)
#define pd(n) printf("%lf\n", n)
#define pl(n) printf("%lld\n", n)
#define ps(str) printf("%s\n", str)
#define ms(n, m) memset(n, m, sizeof(n))
int n, arr[16][16], dp[16][1 << 16];
int solve(int i, int mask)
{
if(i >= n)
return 0;
if(dp[i][mask] != -1)
return dp[i][mask];
for(int cur = 0; cur < n; ++cur)
{
if(!(mask & (1 << cur)))
dp[i][mask] = max(dp[i][mask], arr[i][cur] + solve(i + 1, mask | (1 << cur)));
}
return dp[i][mask];
}
int main()
{
int test, cs = 1;
sf(test);
while(test--)
{
ms(dp, -1);
sf(n);
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < n; ++j)
sf(arr[i][j]);
}
printf("Case %d: %d\n", cs++, solve(0, 0));
}
return 0;
}