lightoj1011 - Marriage Ceremonies【状压dp】
来源:互联网 发布:淘宝店铺分类怎么修改 编辑:程序博客网 时间:2024/06/16 02:33
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
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<queue>#include<list>#include<vector>#include<cmath>using namespace std;const int maxn=10010;int dp[1<<16];int n,m;int map[20][20];int dfs(int s,int cnt){ if(s==(1<<n)-1)return dp[s]=0; if(dp[s]!=-1)return dp[s]; for(int i=0;i<n;++i){ if(!(s&(1<<i))){ dp[s]=max(dp[s],dfs(s|(1<<i),cnt+1)+map[cnt][i]); } } return dp[s];}int main(){ int t,i,j,k,test=1; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;++i){ for(j=0;j<n;++j){ scanf("%d",&map[i][j]); } } memset(dp,-1,sizeof(dp)); printf("Case %d: %d\n",test++,dfs(0,0)); } return 0;}
- LightOJ1011---Marriage Ceremonies (状压dp)
- lightoj1011 - Marriage Ceremonies【状压dp】
- 【DP】 LightOJ 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)
- light oj 1011 - Marriage Ceremonies (状压 dp)
- 1011 - Marriage Ceremonies(状压dp)
- lightoj 1011 Marriage Ceremonies (状压dp)
- LightOJ 1011 - Marriage Ceremonies (dp)
- light oj 1011 marriage ceremonies (状压dp)
- lightoj 1011 - Marriage Ceremonies 【状压dp or KM】
- lightoj 1011 - Marriage Ceremonies 详解(状压DP入门题)
- Lightoj 1011 Marriage Ceremonies(状压dp入门 or km板子)
- 1011 - Marriage Ceremonies[状态压缩dp]
- LightOJ 1011 - Marriage Ceremonies(dp)
- linux大文件查找
- 关于iOS中的textView
- iOS学习笔记74- 完整详解GCD系列(三)dispatch_group
- Unable to load native-hadoop library for your platform...
- 安卓开发工具汇总,开发人员必备!
- lightoj1011 - Marriage Ceremonies【状压dp】
- [Java] 接口(Interface)与 抽象类 (Abstract)使用规则和区别
- 百度关于PC站与手机站适配
- SQL Server超连接查询
- swift2.0 学习笔记Two
- iOS学习笔记74-完整详解GCD系列(四)dispatch_semaphore(信号量)
- Laravel 5.2 $errors 不正常工作
- Node.js---1.Node.js的特点
- Android:处理ListView条目中的Button的点击事件和条目点击事件冲突