- #include <bits/stdc++.h>
- using namespace std;
- int dp[18][1<<18], n;
- #define check(n, pos) (n & (1<<pos))
- #define sett(n, pos) (n | (1<<pos))
- int a[18][18];
- int go(int i, int mask){
- if(i == n){
- return 0;
- }
- if(dp[i][mask] != -1){
- return dp[i][mask];
- }
- int ans = -1;
- for(int j = 0; j <n;j++){
- if(!check(mask, j)){
- ans = max(ans, a[i][j] + go(i+1,sett(mask, j)));
- }
- }
- return dp[i][mask] = ans;
- }
- int main()
- {
- int ts, cs = 1;
- cin>>ts;
- while(ts--){
- cin>>n;
- memset(dp, -1, sizeof(dp));
- for(int i = 0; i<n; i++){
- for(int j = 0; j <n; j++){
- cin>>a[i][j];
- }
- }
- printf("Case %d: %d\n",cs, go(0, 0));
- cs++;
- }
- return 0;
- }
Thursday, 27 July 2017
Lightoj 1011 - Marriage Ceremonies
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment