热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Lightoj1011MarriageCeremonies

1011-MarriageCeremoniesPDF(English)StatisticsForumTimeLimit:2second(s)MemoryLimit:32MBYouw

1011 - Marriage Ceremonies











技术分享   技术分享 PDF (English) Statistics Forum










Time Limit: 2 second(s)Memory Limit: 32 MB


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

 




Problem Setter: Jane Alam Jan

题意:就是让你每排选一个人,并且排每列上不可以有多个人。

思路:状压dp;dp[i][j]表示前i个人选,在状态j时的最大值,状态转移方程   dp[i][j]=max(dp[i][j],dp[i-1][z]+ma[i][u]);u表示当前i这一个位置选的是ma[i][u]那个点。

由于 我想先把表打出来,也就是记录每个i,的j的各个状态的表,然后超内存,之后dp改成滚动数组还超,所以我就先把5到16的表打出来,然后前面按不打表的方式循环,后面直接查表,A了。时间复杂度也小了,大概为(n*(1<


1 #include
2 #include
3 #include
4 #include<string.h>
5 #include
6 #include
7 using namespace std;
8 typedef long long LL;
9 typedef unsigned long long ll;
10 int dp[2][1<<16];
11 int ma[17][17];
12 typedef struct pp
13 {
14 int x;
15 int id;
16 } ss;
17 vectorvec[12][1<<16];
18 int main(void)
19 {
20 int i,j,k,p,q;
21 int s;
22 for(i=5; i<=16; i++)
23 {
24 for(j=(1<<(i-1)); j<1<<16; j++)
25 {
26 int ans=0;
27 int uu=j;
28 while(uu)
29 {
30 if(uu%2)ans++;
31 uu/=2;
32 }
33 if(ans==i)
34 {
35 for(s=1; s<=16; s++)
36 {
37 if(((1<<(s-1))&j))
38 {
39 ss dd;
40 dd.x=(1<<(s-1)^j);
41 dd.id=s;
42 vec[i-5][j].push_back(dd);
43 }
44 }
45 }
46 }
47 }
48 scanf("%d",&k);
49 for(s=1; s<=k; s++)
50 {
51 scanf("%d",&p);
52 for(i=1; i<=p; i++)
53 {
54 for(j=1; j<=p; j++)
55 {
56 scanf("%d",&ma[i][j]);
57 }
58 }
59 int u;
60 int maxx=0;
61 memset(dp,0,sizeof(dp));
62 for(i=1; i<=4&&i<=p; i++)
63 { int k=i%2;
64 for(j=(1<<(i-1)); j<(1<)
65 {
66 for(u=1; u<=p; u++)
67 {
68 if((1<<(u-1))&j)
69 {
70 int z=(1<<(u-1))^j;
71 dp[k][j]=max(dp[k][j],dp[(k+1)%2][z]+ma[i][u]);
72 maxx=max(dp[k][j],maxx);
73 }
74 }
75 }
76 }
77 for(i=5; i<=(p); i++)
78 {
79 int k=i%2;
80 for(j=(1<<(i-1)); j<(1<)
81 {
82 for(u=0; u5][j].size(); u++)
83 {
84 ss kk=vec[i-5][j][u];
85 if(kk.id<=p)
86 {
87 dp[k][j]=max(dp[k][j],dp[(k+1)%2][kk.x]+ma[i][kk.id]);
88 maxx=max(dp[k][j],maxx);
89 }
90 }
91 }
92 }
93 printf("Case %d: ",s);
94 printf("%d\n",maxx);
95 }
96 return 0;
97 }

 


 

 




 

 


 




Problem Setter: Jane Alam Jan












Developed and Maintained by
JANE ALAM JAN



Copyright © 2012

LightOJ, Jane Alam Jan


 


推荐阅读
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 本文探讨了如何通过最小生成树(MST)来计算严格次小生成树。在处理过程中,需特别注意所有边权重相等的情况,以避免错误。我们首先构建最小生成树,然后枚举每条非树边,检查其是否能形成更优的次小生成树。 ... [详细]
  • QUIC协议:快速UDP互联网连接
    QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 深入理解 Oracle 存储函数:计算员工年收入
    本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • 在Linux系统中配置并启动ActiveMQ
    本文详细介绍了如何在Linux环境中安装和配置ActiveMQ,包括端口开放及防火墙设置。通过本文,您可以掌握完整的ActiveMQ部署流程,确保其在网络环境中正常运行。 ... [详细]
  • 如何在WPS Office for Mac中调整Word文档的文字排列方向
    本文将详细介绍如何使用最新版WPS Office for Mac调整Word文档中的文字排列方向。通过这些步骤,用户可以轻松更改文本的水平或垂直排列方式,以满足不同的排版需求。 ... [详细]
  • 理解存储器的层次结构有助于程序员优化程序性能,通过合理安排数据在不同层级的存储位置,提升CPU的数据访问速度。本文详细探讨了静态随机访问存储器(SRAM)和动态随机访问存储器(DRAM)的工作原理及其应用场景,并介绍了存储器模块中的数据存取过程及局部性原理。 ... [详细]
  • 几何画板展示电场线与等势面的交互关系
    几何画板是一款功能强大的物理教学软件,具备丰富的绘图和度量工具。它不仅能够模拟物理实验过程,还能通过定量分析揭示物理现象背后的规律,尤其适用于难以在实际实验中展示的内容。本文将介绍如何使用几何画板演示电场线与等势面之间的关系。 ... [详细]
author-avatar
敬昇文军3546
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有