poj2490
2016-07-13 15:52
274 查看
#include <iostream> #include<cstdio> #include<cmath> #include<string> #include<cstring> #include<algorithm> using namespace std; const int maxn = 15; const int inf = 0x3f3f3f3f; int n; int maxdep; int a[maxn][maxn]; int f[(1<<maxn)][maxn]; int main() { // freopen("in.txt","r",stdin); int T; cin>>T; for(int tt=1;tt<=T;tt++) { cin>>n; maxdep=(1<<n)-1; memset(f,0x3f,sizeof f); for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j]; for(int i=0;i<n;i++) f[1<<i][1]=a[i][i]; for(int i=2;i<=n;i++) { for(int j=0;j<maxdep;j++) { if(f[j][i-1]==inf) continue; for(int k=0;k<n;k++) { if((j>>k)&1) continue; int newj = j^(1<<k); int p = f[j][i-1]; for(int l=0;l<n;l++) { if((newj>>l)&1) p+=a[l][k]; } if(f[newj][i]>p) f[newj][i]=p; } } } printf("Case %d: %d\n",tt,f[maxdep] ); } return 0; }
相关文章推荐
- 计算机术语,慢慢积累中
- python调用java编写的Webservice
- Spring aop--4不同的使用方式
- php DOM模型对象操作XML格式的数据 增、删、改、查
- SLAM: RtabMap中文解析
- Retrofit2 的使用以及总结
- readlink
- maven各种奇葩问题
- 获取相册里所选视频对应的nsurl
- CDH4 动态添加datanode和nodemanager
- 关于tomcat的种种问题,异常,出错
- NYOJ 739 卖股票
- 分组对称加密模式:ECB/CBC/CFB/OFB缺CTR
- com.mysql.jdbc.driver中resultset报NullException
- Leetcode 9. Palindrome Number (Easy) (cpp)
- 把url参数转化成一个对象返回
- Javascript数组与字典用法分析
- 获取验证码 60秒倒计时 setInterval
- 评价图像质量的新方式SSIM
- JavaScript try/catch/finally 语句