Marriage Ceremonies--Light OJ 1011
来源:互联网 发布:webgl高级编程pdf下载 编辑:程序博客网 时间:2024/06/16 05:42
- Marriage Ceremonies
- 题目位置
- 题目
- 做法
- 代码
Marriage Ceremonies
题目位置:
Light OJ 1011
题目:
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.InputInput 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.OutputFor each case, print the case number and the maximum possible priority index after all the marriages have been arranged.
Sample Input
2
2
1 5
2 1
3
1 2 3
6 5 4
8 1 2
Sample Output
Case 1: 7
Case 2: 16
做法
就是想到了到了第i号男人的选定的时候,就是会有i-1位女嘉宾被选了!
所以在枚举状态的时候就是加上一个判断二进制 1 的个数的函数!
别的和普通状压DP是一样的!
数二进制有几个 1 :__builtin_popcount()
代码
#include <bits/stdc++.h>using namespace std;#define N 18int T,n,k;int dp[N][1<<N],a[N][N];int main(){ scanf("%d",&T); for(int loc=1; loc<=T; loc++) { scanf("%d",&n); memset(dp,0,sizeof(dp)); for(int i=0; i<n; i++) for(int j=0; j<n; j++) scanf("%d",&a[i][j]); int final=1<<n; for(int i=0;i<n;i++) dp[0][1<<i]=a[0][i]; for(int i=1; i<n; i++) for(int used=0; used<final; used++) if(__builtin_popcount(used)==i) for(int j=0; j<n; j++) if(!(used & (1<<j))) { dp[i][used|(1<<j)]=max(dp[i-1][used]+a[i][j],dp[i][used|(1<<j)]); } printf("Case %d: %d\n",loc,dp[n-1][final-1]); } return 0;}
阅读全文
0 0
- Marriage Ceremonies--Light OJ 1011
- light oj 1011 Marriage Ceremonies(状压DP)
- light oj 1011 - Marriage Ceremonies (状压 dp)
- light 1011 - Marriage Ceremonies
- light oj 1011 - Marriage Ceremonies (状态压缩+记忆化搜索)
- Light OJ 1011 Marriage Ceremonies 状态压缩DP
- light oj 1011 marriage ceremonies (状压dp)
- Light 1011 - Marriage Ceremonies (费用流)
- lightoj 1011 Marriage Ceremonies
- LightOJ 1011 - Marriage Ceremonies
- LightOJ 1011 Marriage Ceremonies
- 1011 - Marriage Ceremonies
- LightOJ 1011 Marriage Ceremonies
- LightOJ 1011 - Marriage Ceremonies (dp)
- Marriage Ceremonies
- 1011 - Marriage Ceremonies[状态压缩dp]
- 【DP】 LightOJ 1011 - Marriage Ceremonies状压
- LightOJ 1011 Marriage Ceremonies【状压DP】
- request,response,session,application四者之间的作用域联系以及各自的运行机制
- JS作用域详解
- Shiro使用步骤
- easyui combox数据的动态绑定
- ItelliJ IDEA开发工具使用—创建一个web项目
- Marriage Ceremonies--Light OJ 1011
- git 学习笔记及常用命令
- 关于获取本地系统时间问题
- 常微分实验(1.1) 变量分离方程与变量变换
- Java中ArrayList、Vector与LinkedList有什么区别
- Android 获取资源目录下的文件
- Glide基本使用
- codeforces 182D KMP+math
- Windows下常用的100个CMD指令以及常见的操作