(状压) Marriage Ceremonies (lightOJ 1011)
http://www.lightoj.com/volume_showproblem.php?problem=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.
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 <cstring>
#include <queue>
#include <algorithm> using namespace std; #define N 1100 #define met(a,b) (memset(a,b,sizeof(a)))
typedef long long LL; int a[][], dp[][(<<)]; int main()
{
int T, iCase=; scanf("%d", &T); while(T--)
{
int n, i, j, k, K; scanf("%d", &n); for(i=; i<=n; i++)
for(j=; j<=n; j++)
scanf("%d", &a[i][j]); K = (<<n)-;
for(i=; i<=n; i++)
{
for(j=; j<=K; j++)
{
dp[i][j] = ;
int cnt = ;
for(k=; k<n; k++)///cnt算出j这个状态有多少个人匹配
if(j&(<<k)) cnt++;
///如果有i个人匹配, 便可进行下面的状态转化
if(cnt!=i) continue;
for(k=; k<=n; k++)
{
if( (j&(<<(k-))) )
dp[i][j] = max(dp[i][j], dp[i-][j-(<<(k-))]+a[i][k]);
}
}
} printf("Case %d: %d\n", iCase++, dp[n][K]);
}
return ;
}
(状压) Marriage Ceremonies (lightOJ 1011)的更多相关文章
- Marriage Ceremonies LightOJ - 1011
Marriage Ceremonies LightOJ - 1011 常规状压dp.popcount(S)表示S集合中元素数量.ans[S]表示S中的女性与前popcount(S)个男性结婚的最大收益 ...
- Light OJ 1011 - Marriage Ceremonies(状压DP)
题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少? 状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...
- Lightoj 1011 - Marriage Ceremonies
You work in a company which organizes marriages. Marriages are not that easy to be made, so, the job ...
- lightoj 1158 - Anagram Division(记忆化搜索+状压)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1158 题解:这题看起来就像是记忆搜索,由于s很少最多就10位所以可以考虑用状压 ...
- lightoj 1086 - Jogging Trails(状压dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1086 题解:题目就是求欧拉回路然后怎么判断有欧拉回路只要所有点的度数为偶数.那 ...
- lightoj 1061 - N Queen Again(状压dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1061 题解:显然能满足情况的8皇后的摆法不多,于是便可以用题目给出的状态来匹配 ...
- lightoj 1119 - Pimp My Ride(状压dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1119 题解:状压dp存一下车有没有被搞过的状态就行. #include < ...
- lightoj 1037 - Agent 47(状压dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1037 #include <iostream> #include & ...
- Lightoj1011 - Marriage Ceremonies
1011 - Marriage Ceremonies PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
随机推荐
- 云存储性能测试工具--COSBench安装
COSBench安装 Cosbench是Intel的开源云存储性能测试软件,COSBench目前已经广泛使用与云存储测试,并作为云存储的基准测试工具使用 1 环境 1.1 操作系统 COSBench可 ...
- CSS基础篇
写的不错,收藏 http://www.cnblogs.com/suoning/p/5625582.html
- openldap加密传输sssd
http://blog.father.gedow.net/2015/09/29/sssd-ldap-sudo/ yum -y install openldap-clients sssd authcon ...
- [转载]:经纬度与WGS84坐标转换
本代码实现在WGS84系统的大地坐标(BLH)和空间直角坐标(XYZ)的互相转换,符合标准语法,可直接使用 如下代码,输出为: WGS84: -2175790.73969891 4461032 ...
- tp框架 中的时间 查询范围
$where['add_time'] = array(array('egt',$starttime),array('elt',$endtime),'AND');
- a标签截字
首先要给A标签设置宽度,需要把A标签变为块级元素 display:block:或者 display:inline-block: 然后设置宽度,溢出隐藏,强制不换行这几个属性. a { display: ...
- Python Django之路由系统
1.初识路由系统 路由系统是用户发请求到URL,然后URL根据路由系统重新指向到函数名的一个对应关系 2.创建project和app django-admin startproject mysite ...
- CentOS6 搭建Git仓库
近期上了Redmine以后,系统集成了Git的联动功能,于是萌生了搭建内网仓库的想法,特此记录一下: 1.安装Git yum -y install git 2.创建用户及密码 useradd git ...
- svn 命令行创建和删除 分支和tags
创建分支 svn cp -m "create branch" http://svn_server/xxx_repository/trunk http://svn_server/xx ...
- HTML DOM appendChild() 方法
<!DOCTYPE html> <html> <body> <ul id="myList"> <li>Coffee< ...