1011 - Marriage Ceremonies
来源:互联网 发布:网络存在安全隐患 编辑:程序博客网 时间:2024/06/06 13:03
http://lightoj.com/volume_showproblem.php?problem=1011
状压dp
You work in a company which organizes marriages. Marriages are not that easy to be made, so, the job is quite hard for you.
The job gets more difficult when people come here and give their bio-data with their preference about opposite gender. Some give priorities to family background, some give priorities to education, etc.
Now your company is in a danger and you want to save your company from this financial crisis by arranging as much marriages as possible. So, you collect N bio-data of men and N bio-data of women. After analyzing quite a lot you calculated the priority index of each pair of men and women.
Finally you want to arrange N marriage ceremonies, such that the total priority index is maximized. Remember that each man should be paired with a woman and only monogamous families should be formed.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains an integer N (1 ≤ n ≤ 16), denoting the number of men or women. Each of the next N lines will contain N integers each. The jthinteger in the ith line denotes the priority index between the ith man and jth woman. All the integers will be positive and not greater than 10000.
Output
For each case, print the case number and the maximum possible priority index after all the marriages have been arranged.
Sample Input
Output for Sample Input
2
2
1 5
2 1
3
1 2 3
6 5 4
8 1 2
Case 1: 7
Case 2: 16
设dp[i][j]表示前i行状态为j的最大值,这一题跟放花那一题有什么区别呢?为什么不能像放花一样解,原因在与放花那一题有前i朵花怎么放这么一个子问题,这一题却没有,因为没有顺序。
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#define LL long longusing namespace std;const int maxn=1<<30;const int SIZE=1e2+10;int cmap[20][20],dp[17][70000];int main(){ int T,n; scanf("%d",&T); for(int cas=1;cas<=T;cas++){ scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&cmap[i][j]); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){//第i行枚举前i-1行状态j for(int j=0;j<(1<<n);j++){ int cnt=0; for(int k=0;k<n;k++){ if(j&(1<<k))cnt++; } if(cnt!=i-1)continue; for(int k=0;k<n;k++){ if(j&(1<<k))continue; dp[i][j|(1<<k)]=max(dp[i][j|(1<<k)],dp[i-1][j]+cmap[i][k+1]);//注意是第k+1个位置可以放 } } } printf("Case %d: %d\n",cas,dp[n][(1<<n)-1]); } return 0;}
- lightoj 1011 Marriage Ceremonies
- LightOJ 1011 - Marriage Ceremonies
- LightOJ 1011 Marriage Ceremonies
- 1011 - Marriage Ceremonies
- LightOJ 1011 Marriage Ceremonies
- light 1011 - Marriage Ceremonies
- LightOJ 1011 - Marriage Ceremonies (dp)
- Marriage Ceremonies--Light OJ 1011
- Marriage Ceremonies
- 1011 - Marriage Ceremonies[状态压缩dp]
- 【DP】 LightOJ 1011 - Marriage Ceremonies状压
- Light 1011 - Marriage Ceremonies (费用流)
- LightOJ 1011 Marriage Ceremonies【状压DP】
- light oj 1011 Marriage Ceremonies(状压DP)
- LightOJ 1011 - Marriage Ceremonies (状压dp)
- LightOJ - 1011 Marriage Ceremonies(状压DP)
- LightOJ 1011 - Marriage Ceremonies(dp)
- LightOJ 1011 - Marriage Ceremonies(状压DP)
- iOS UILable常用属性总结
- ASP+Access的安全隐患及对策
- chrome 去掉每次打开都是hao123
- ubuntu无法识别usb设备
- Java再学习-算法之选择排序
- 1011 - Marriage Ceremonies
- java中synchronize的总结
- testlink xml转excel
- 使用Excel进行无重复双因素方差分析
- linux下mongodb的安装以及扩展的安装
- Android中启动页ViewPager和ViewFlipper带指示器
- 苹果:6月1日后所有应用必须支持IPv6-only网络
- 【转载】IntelliJ Idea 常用快捷键列表
- Android Studio适当修改