light oj 1011 一个普通记录...(路径?)的状压dp
来源:互联网 发布:wifislax秒破wpa2网络 编辑:程序博客网 时间:2024/04/23 23:58
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 jth integer 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
这个题看见n<=16基本上就可以往状压上面想了…
dp数组存的是每个男生的不同状态
p这个结构体里边存的是每个女生是否结婚的状态
然后每当状态转移的时候连哪个女生是否婚配一起转移…
新加上的那个就标记好…
#include <iostream>#include<cstdio>#include<vector>#include<algorithm>#include<cmath>#include<memory.h>using namespace std;int zhi[17][17],n,u=0;struct p{ int zhi; bool shi[17];};p dp[1<<17];int main(){ int T; cin>>T; while(T--) { cin>>n; memset(zhi,0,sizeof(zhi)); memset(dp,0,sizeof(dp)); for(int a=1;a<=n;a++)for(int b=1;b<=n;b++)scanf("%d",&zhi[a][b]); int quan=1<<n; for(int a=1;a<quan;a++) { for(int b=n-1;b>=0;b--) { int ce=1<<b; if(ce&a) { int qian=a-ce; int maxx=0; int weizhi; for(int c=1;c<=n;c++) { if(dp[qian].shi[c]==0) { if(maxx<zhi[b+1][c]) { maxx=zhi[b+1][c]; weizhi=c; } } } p q=dp[qian]; if(dp[a].zhi<q.zhi+maxx) { q.shi[weizhi]=1; q.zhi+=maxx; dp[a]=q; } } } } printf("Case %d: %d\n",++u,dp[quan-1].zhi); } return 0;}
- light oj 1011 一个普通记录...(路径?)的状压dp
- Light OJ 1110 An Easy LCS (DP+路径记录)
- light oj 1110 LCS 记录路径
- Light Oj 1194 colored T-shirts 经典状压dp
- Light OJ 1119 Pimp My Ride (简单状压DP)
- light oj 1011 marriage ceremonies (状压dp)
- Light OJ 1110 - An Easy LCS (LCS+字典序最小路径记录)
- light oj 1011 Marriage Ceremonies(状压DP)
- light oj 1011 - Marriage Ceremonies (状压 dp)
- Light oj 1025 (区间dp)
- Light oj 1068 - Investigation(数位dp)
- light Oj 1013 - Love Calculator (dp)
- light oj 1017 - Brush (III) (dp)
- light oj 1031(区间dp入门)
- light oj 1031(区间dp+博弈)
- 【light-oj】-1047 - Neighbor House(dp)
- light oj 1422(区间dp 水题)
- light oj 1032 数位DP
- Java类加载机制
- Android 集成融云IM(一) 前提准备和获取Token
- Very Deep Convolutional Networks for Large-Scale Image Recognition(VGG模型)
- 1113 - Discover the Web (栈)
- 【OVS2.5.0源码分析】datapath之action分析(8)
- light oj 1011 一个普通记录...(路径?)的状压dp
- ROS使用教程-关于rosparam
- java代码优化细节
- queue和stack容器
- Ubuntu14.04下Fast-RCNN配置VGG16.caffemodel
- OC 类的使用
- 第二周项目三-体验复杂度
- 算法竞赛入门经典第二版第一章语言篇
- leetcode Count of Range Sum