Marriage Ceremonies LightOJ - 1011

常规状压dp。popcount(S)表示S集合中元素数量。ans[S]表示S中的女性与前popcount(S)个男性结婚的最大收益。

那么,$ans[S]=max\{ans[S-p]+a[popcount(S)][p]\}$

老代码

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[][],a[][],T,TT,n;
int main()
{
int i,j,k;
scanf("%d",&T);
for(TT=;TT<=T;TT++)
{
scanf("%d",&n);
for(i=;i<=n;i++)
for(j=;j<=n;j++)
scanf("%d",&a[i][j]);
memset(ans,,sizeof(ans));
for(i=;i<=n;i++)
for(j=;j<(<<n);j++)
{
if(__builtin_popcount(j)!=i) continue;
for(k=;k<=n;k++)
if(j&(<<(k-)))
ans[i][j]=max(ans[i][j],ans[i-][j^(<<(k-))]+a[i][k]);
}
printf("Case %d: %d\n",TT,ans[n][(<<n)-]);
}
return ;
}

新代码

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[],a[][],T,TT,n;
int main()
{
int i,j,k;
scanf("%d",&T);
for(TT=;TT<=T;TT++)
{
scanf("%d",&n);
for(i=;i<=n;i++)
for(j=;j<=n;j++)
scanf("%d",&a[i][j]);
memset(ans,,sizeof(ans));
for(i=;i<(<<n);i++)
for(j=;j<=n;j++)
if(i&(<<(j-)))
ans[i]=max(ans[i],ans[i^(<<(j-))]+a[__builtin_popcount(i)][j]);
printf("Case %d: %d\n",TT,ans[(<<n)-]);
}
}

另:貌似可以用二分图最大完美匹配做

Marriage Ceremonies LightOJ - 1011的更多相关文章

  1. (状压) Marriage Ceremonies (lightOJ 1011)

    http://www.lightoj.com/volume_showproblem.php?problem=1011 You work in a company which organizes mar ...

  2. Lightoj 1011 - Marriage Ceremonies

    You work in a company which organizes marriages. Marriages are not that easy to be made, so, the job ...

  3. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  4. Lightoj1011 - Marriage Ceremonies

    1011 - Marriage Ceremonies   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  5. Light OJ 1011 - Marriage Ceremonies(状压DP)

    题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少?   状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...

  6. light oj 1011 - Marriage Ceremonies

    题目大意: 给出n*n的矩阵Map,Map[i][j]代表第i个男人和第j个女人之间的满意度,求男女一一配对后,最大的满意度之和. 题目思路:状态压缩 题目可看做每行取一点,所有点不同列的情况下,各个 ...

  7. light oj 1011 - Marriage Ceremonies (状态压缩+记忆化搜索)

    题目链接 大概题意是有n个男的n个女的(原谅我这么说,我是粗人),给你一个n*n的矩阵,第i行第j列表示第i个女(男)对第j个男(女)的好感度,然后要安排n对相亲,保证都是正常的(无搞基百合之类的), ...

  8. lightoj 1011 最大权重匹配或最大费用流

    由于暂时不会KM算法,只能用最大费用流来做了. 题目链接:http://lightoj.com/volume_showproblem.php?problem=1011 #include <cst ...

  9. lightoj 1011 (状态压缩dp)

    思路:状态压缩dp,设dp[i][j] 表示前i行,状态为j时的最大值,状态定义为:若前i行中取了第x列那么j的二进制位中第x位为1,否则为0,最后答案就是dp[n-1][(1 << n) ...

随机推荐

  1. NAND flash坏区

    计算容量 厂家所说的4G指的是4 000 000 000字节,是按1000进制计算的,而电脑是按照1024进制计算的,所以标称为4G的NAND Flash理论容量是4 000 000 000 / 10 ...

  2. LeetCode(67)题解: Add Binary

    https://leetcode.com/problems/add-binary/ 题目: Given two binary strings, return their sum (also a bin ...

  3. CentOS笔记-目录结构(转载了菜鸟教程里的)

    在linux系统中,有几个目录是比较重要的,平时需要注意不要误删除或者随意更改内部文件. /etc: 上边也提到了,这个是系统中的配置文件,如果你更改了该目录下的某个文件可能会导致系统不能启动. /b ...

  4. Maven group, artifact or version defined in the pom file do not match the file ...

    在把library上传到bintray空间的时候报以下错误 Could not upload to 'https://api.bintray.com/content/ping/maven/comm-a ...

  5. SpringMVC+ajaxFileUpload上传图片 IE浏览器弹下载框问题解决方式

    如题,简单记录一下这个问题的解决的方法,导致问题的核心原因是:ajaxfileupload不支持响应头ContentType为application/json的设置.而且IE也不支持这样的格式,而当我 ...

  6. kaminari分页插件样式

    修改国际化文件,zh-cn views: pagination: first: "首页" last: "尾页" previous: "上一页" ...

  7. HDU4292 Food —— 最大流 + 拆点

    题目链接:https://vjudge.net/problem/HDU-4292 Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  8. POJ - 2142 The Balance(扩展欧几里得求解不定方程)

    d.用2种砝码,质量分别为a和b,称出质量为d的物品.求所用的砝码总数量最小(x+y最小),并且总质量最小(ax+by最小). s.扩展欧几里得求解不定方程. 设ax+by=d. 题意说不定方程一定有 ...

  9. Tomcat 系统架构与设计模式之二

    Tomcat 系统架构与设计模式,第 2 部分: 设计模式分析 来自:http://www.ibm.com/developerworks/cn/java/j-lo-tomcat2/ 这个分为两个部分的 ...

  10. VC++编译说明

    目录 第1章编译步骤    1 第2章编译源文件    2 2.1 编译器    2 2.2 包含头文件    3 2.3 重复包含    6 2.4 预编译头文件    7 2.4.1 创建     ...