UESTC_The Most Wonderful Competition CDOJ 56

The Most Wonderful Competition

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

Submit Status

Last week, School of Applied Mathematics held a competition of flying kite, contestants are divided into pairs, and one contestant competes with another in each pair. As we know, different way dividing pairs may bring different splendid level value, which appears as a real numbers. Now Miss Ye wants to know how to divide the competitor in order to attain maximum splendid level.

Input

The first line of the input contains one integer T, which indicate the number of test case.

For each test case, in the first line there is an integer N (N≤16, N is always an even number) indicating there are N contestants taking part the competition.

In the next N line, each line contains N real numbers. The j-th number in the i-th line is the splendid level value when the i-th contestant and the j-th constant are made in one pair. You can assume the j-th number in the i-th line is equal to the i-th number in the j-th line.

Output

For each case, output the maximum total splendid level value accurate to two digits after the radix point.

Sample input and output

Sample Input Sample Output
1
2
0.0 1.0
1.0 0.0
1

Source

电子科技大学第七届ACM程序设计大赛 初赛

解题报告

简单集合DP,f(i)表示选择这i个元素时的最高加成

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5
 6 using namespace std;
 7 const int maxn = 16 + 15;
 8 double value[maxn][maxn];
 9 double f[1 << 16];
10 bool   arrive[1<<16];
11 int n;
12 double ans;
13
14
15 double dfs(int cur,int val)
16 {
17   if (arrive[val])
18    return f[val];
19   arrive[val] = true;
20   double &ans = f[val] = -1e100;
21   if (val)
22    {
23          for(int i = 0 ; i < n ; ++ i)
24           if (val >> i & 1 && i != cur)
25            {
26               int next = 1;
27               int newval = val;
28               newval &= ~(1 << i);
29               newval &= ~(1 << cur);
30               for(int j = 0 ; j < n ; ++ j)
31                if (newval >> j & 1)
32                 {
33                     next = j;
34                     break;
35                 }
36               ans = max(ans,dfs(next,newval) + value[cur][i] );
37            }
38    }
39   else
40    ans = 0;
41   return ans;
42 }
43
44 int main(int argc,char *argv[])
45 {
46   int Case;
47   scanf("%d",&Case);
48   while(Case--)
49    {
50          memset(arrive,false,sizeof(arrive));
51          scanf("%d",&n);
52          for(int i = 0 ; i < n ; ++ i)
53           for(int j = 0 ; j < n ; ++ j)
54            scanf("%lf",&value[i][j]);
55          dfs(0,(1<<n)-1);
56          printf("%.2lf\n",f[(1<<n)-1]);
57    }
58   return 0;
59 }
时间: 2024-07-29 19:07:57

UESTC_The Most Wonderful Competition CDOJ 56的相关文章

Kaggle Competition Past Solutions

Kaggle Competition Past Solutions We learn more from code, and from great code. Not necessarily always the 1st ranking solution, because we also learn what makes a stellar and just a good solution. I will post solutions I came upon so we can all lear

TC Asia Competition

250PT不说了.很水得一题. 500PT 给定n(<=1e18),求最大的因子,且这个因子为完全平方,假设这个因子为x那么满足x*x*y = n, 一直枚举因子到n^(1/3)就可以了. 最后判断一下剩余的是不是完全平方. 1000PT 一个排列组合题,一个中心出发有k条路,路与路之间有且仅有中心这个交点.现在要建n个城市,编号1~n,使得中心有一个城市,每条路末端有一个城市,然后其余城市就放在各条路的中间.首先保证中心和末端处各建设1个城市,问 总共有多少种安排方式.两种安排方式不同,表示至

Lession 5-6 When you have a cold

一 生词 sufferer 患者 sneeze打喷嚏 fever 发烧 nasal 鼻的 a runny nose流鼻涕 passage 一段,通道 stage 阶段,舞台 aspirin阿司匹林 mutual 共同的 ailment 疾病 insomnia 失眠 pace 步伐,加快 vodka 伏尔加酒 bathroom 浴室,厕所 migraine 偏头痛 go about处理 e.g. How did you actually go about making this marvelous

Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 预处理优化】

传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A multi-subject competition is coming! The competition has mm 

java面试一定会遇到的56个面试题

1.问题:如果main方法被声明为private会怎样? 答案:能正常编译,但运行的时候会提示"main方法不是public的". 2.问题:Java里的传引用和传值的区别是什么? 答案:传引用是指传递的是地址而不是值本身,传值则是传递值的一份拷贝. 3.问题:如果要重写一个对象的equals方法,还要考虑什么? 答案:hashCode. 4.问题:Java的"一次编写,处处运行"是如何实现的? 答案:Java程序会被编译成字节码组成的class文件,这些字节码可以

20多岁学习编程晚吗?看看56岁的大叔如何克服自我怀疑学习编程

原文地址:http://mp.weixin.qq.com/s/zzoPGDS5eELxEeO_zfG20w 版权声明 本文首发自微信公共帐号: 学习学习再学习(xiaolai-xuexi) 无需授权即可转载, 甚至无需保留以上版权声明: 转载时请务必注明作者. 我 56 岁了,正在学编程. 为什么?因为我喜欢编程,现在也算得上是老司机了. 但是编程并不简单,学编程很难,不过我还可以接受. 我喜欢沉浸在算法带来的挑战中,也愿意挤出几分钟多进行一次测试,更爱"也许这一次就成功了"之后&qu

Android:刚6瓶啤酒4两56度白酒下肚,居然20分钟做了一手机版网站 !

刚6瓶啤酒4两56度白酒下肚,居然20分钟不到时间做了一手机版网站 !人有多大潜力你知道吗? 大家有兴趣的可以用手机或微信打开 http://xh.yunxunmi.com/ 看看俺这酒后之做! 更多0

距离第一天去实习过去了56天 ::写写自己的想法

1.从前端说起 HTML从最初的那些标签,什么都不懂,<br>    等 不懂<head><body> 这些简单的标签 HTML就最为印象深刻的是: <input type=button  value="点击" onclick=function() >  然后写调用的js函数 <input type="text"  id="lcy">  然后$("#lcy").cli

CDOJ 1273 God Qing&#39;s circuital law

暴力枚举+idea.做的时候mod写错了,写成了1000000009,找了两个多小时才发现...... a[1],a[2],a[3]....a[N] b[1],b[2],b[3]....b[N] 首先需要枚举b[1]...b[N]与a[1]进行组合. 然后对a[2]...a[N]从小到大排序 对b[1],b[2],b[3]....b[N] 除当前与a[1]组合的以外,剩下的从大到小排序 然后找出每一个a[i]在不破坏a[0]最大值的情况下最大能与哪一个b[i]配对. 然后从第N个人开始往第2个人