Light OJ 1264 Grouping Friends (DP+枚举子集)
来源:互联网 发布:水木年华知乎 编辑:程序博客网 时间:2024/06/10 16:11
题意:将所有人分若干组,使得每组的不满意值的和最小。
解析:预处理出来每个可能的组的不满意值,再枚举一下自己即可。
[code]:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int INF = 0x3f3f3f3f;int n,d[15][15],f[1<<15],dp[1<<15];void sol(){ int i,j,S,Ed = 1<<n,S_; int ans = INF; for(S = 1;S < Ed;S++){ f[S] = 0; for(i = 0;i < n;i++){ if(!(S>>i&1)) continue; for(j = 0;j < n;j++){ if(i==j||!(S>>j&1)) continue; f[S] += d[i][j]; } } } for(S = 1;S < Ed;S++){ dp[S] = INF; for(S_=S;S_!=0;S_ = (S_-1)&S){ dp[S] = min(dp[S],dp[S^S_]+f[S_]); } } printf("%d\n",dp[Ed-1]);}int main(){ int i,j,cas; scanf("%d",&cas); for(int T=1;T<=cas;T++){ scanf("%d",&n); for(i = 0;i < n;i++){ for(j = 0;j < n;j++) scanf("%d",&d[i][j]); } printf("Case %d: ",T); sol(); } return 0;}
0 0
- Light OJ 1264 Grouping Friends (DP+枚举子集)
- Light OJ 1228 e-Friends (状压DP)
- Light OJ 1228 - e-Friends (状压DP)
- HDU5119 Happy Matt Friends(穷举子集dp)
- light oj 1032 数位DP
- light OJ 1205 数位DP
- light OJ 1068 数位DP
- light oj 1140 数位dp
- light oj 1422,区间dp
- Light OJ 1231(背包dp)
- light oj 1068(数位dp)
- light oj 1422(区间dp)
- light oj 1025 区间dp
- light oj 1032(数位dp)
- Light OJ 1038(概率DP)
- Light OJ 1031 区间dp
- light oj 1004 水DP
- light oj 1248 概率dp
- flazr针对rtmp进行批量直播测试
- Android 学习笔记 1
- 用java实现谷歌PageRank的算法
- 伸展树
- hibernate5(7)操纵对象入门[2]四大对象状态分析
- Light OJ 1264 Grouping Friends (DP+枚举子集)
- iOS证书和.p12文件
- python内建函数sorted方法概述
- poj 2723 Get Luffy Out 2-SAT
- Animation Resources
- git提交到远程库时提示the authenticity of host can't be established
- Android 重构历程(一)
- 数据结构与算法——普通树的定义与C++实现
- 工程中关于class文件的参数在那块设置。