Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://lightoj.com/volume_showproblem.php?problem=1264
- #include <bits/stdc++.h>
- using namespace std;
- #define si(a) scanf("%d",&a)
- #define f first
- #define s second
- #define mp(a,b) make_pair(a,b)
- #define INF 0x3f3f3f3f
- int precal[20004],dp[20004],vis[20004];
- int solve(int msk)
- {
- if(!msk)return 0;
- int &ret=dp[msk];
- if(vis[msk])return ret;
- vis[msk]=1;
- ret=INF;
- for(int sub=msk;sub;sub=(sub-1)&msk)
- ret=min(ret,precal[sub]+solve(msk^sub));
- return ret;
- }
- int cost[20][20];
- int main()
- {
- int t;
- si(t);
- for(int ca=1;ca<=t;ca++){
- int n,i,j;
- si(n);
- int tot=1<<n;
- for(i=0;i<n;i++)for(j=0;j<n;j++)si(cost[i][j]);
- for(int msk=0;msk<tot;msk++){
- precal[msk]=0;
- for(i=0;i<n;i++){
- if(msk&(1<<i))
- for(j=0;j<n;j++){
- if(msk&(1<<j))
- precal[msk]+=cost[i][j];
- }
- }
- }
- memset(vis,0,sizeof(vis));
- printf("Case %d: %d\n",ca,solve(tot-1));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement