Shanghai Regional Online Contest 1004
Shanghai Regional Online Contest 1004
In the ACM International Collegiate Programming Contest, each team consist of three students. And the teams are given 5 hours to solve between 8 and 12 programming problems.
On Mars, there is programming contest, too. Each team consist of N students. The teams are given M hours to solve M programming problems. Each team can use only one computer, but they can’t cooperate to solve a problem. At the beginning of the ith hour, they will get the ith programming problem. They must choose a student to solve this problem and others go out to have a rest. The chosen student will spend an hour time to program this problem. At the end of this hour, he must submit his program. This program is then run on test data and can’t modify any more.
Now, you have to help a team to find a strategy to maximize the expected number of correctly solved problems.
For each problem, each student has a certain probability that correct solve. If the ith student solve the jth problem, the probability of correct solve is Pij .
At any time, the different between any two students’ programming time is not more than 1 hour. For example, if there are 3 students and there are 5 problems. The strategy {1,2,3,1,2}, {1,3,2,2,3} or {2,1,3,3,1} are all legal. But {1,1,3,2,3},{3,1,3,1,2} and {1,2,3,1,1} are all illegal.
You should find a strategy to maximize the expected number of correctly solved problems, if you have know all probability
Input
The first line of the input is T (1 ≤ T ≤ 20), which stands for the number of test cases you need to solve.
The first line of each case contains two integers N ,M (1 ≤ N ≤ 10,1 ≤ M ≤ 1000),denoting the number of students and programming problem, respectively.
The next N lines, each lines contains M real numbers between 0 and 1 , the jth number in the ith line is Pij .
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then a single real number means the maximal expected number of correctly solved problems if this team follow the best strategy, to five digits after the decimal point. Look at the output for sample input for details.
Sample Input
12 30.6 0.3 0.40.3 0.7 0.9
状压dp,dp[i][j]表示解到第i道题时状态是j的最大期望值,j表示n个人与他们最小解题数的差值,容易知道只有二进制位是0的时候可以转移,二进制全1即为0。
当一个状态已经存在时(最优解),则根据他去更新下一个状态,也就是,当更新第i道题的状态时,去找i-1题的状态,然后取最大的值。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define M(a,b) memset(a,b,sizeof(a)) using namespace std; int t;
double num[][];
double dp[][<<];
int n,m;
double max(double a,double b)
{
return a>b?a:b;
} int main()
{
scanf("%d",&t);
int cas = ;
while(t--)
{
scanf("%d%d",&n,&m);
for(int i = ;i<n;i++)
for(int j = ;j<m;j++)
{
scanf("%lf",&num[i][j]);
}
M(dp,);
for(int i = ;i<n;i++)
dp[][<<i] = num[i][];
for(int i = ;i<m;i++)
{
for(int j = ;j<(<<n);j++)
{
if(dp[i-][j])
{ for(int k = ;k<n;k++)
{
if((j&(<<k))==)
{
int tm = j|(<<k);
if(tm==((<<n)-)) tm = ;
dp[i][tm] = max(dp[i][tm],dp[i-][j]+num[k][i]);
//cout<<i<<' '<<tm<<' '<<dp[i][tm]<<' '<<dp[i-1][j]+num[k][i]<<endl;
}
}
}
}
}
double ans = -;
for(int i = ;i<(<<n);i++)
{
if(dp[m-][i]>ans) ans = dp[m-][i];
}
printf("Case #%d: ",cas++);
printf("%.5f\n",ans);
}
return ;
}
这一题还可以用费用流或KM搞,很简单,做m/n次KM就行。
//O(n^3*(m/n))
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define M(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
using namespace std; const double eps=1e-;
int n,m;
double num[][];
int match[];
double slack[];
bool visx[];
bool visy[];
double lx[];
double ly[];
double g[][];
int n1,n2; bool dfs(int x)
{
visx[x] = ;
for(int y = ;y<=n2;y++)
{
if(visy[y])
continue;
double t = lx[x]+ly[y]-g[x][y];
if(fabs(t)<eps)
{
visy[y] = ;
if(match[y]==-||dfs(match[y]))
{
match[y] = x;
return true;
}
}
else if(slack[y]>t)
slack[y] = t;
}
return false;
} double KM()
{
M(ly,);
M(match,-);
int i,j;
for(i = ;i<=n1;i++)
{
for(j = ,lx[i]=-INF;j<=n2;j++)
{
if(g[i][j]>lx[i])
lx[i] = g[i][j];
}
}
for(int k = ;k<=n1;k++)
{
for(j = ;j<=n2;j++)
slack[j] = INF;
while(true)
{
M(visx,false);
M(visy,false);
if(dfs(k)) break;
double t = INF;
for(i = ;i<=n2;i++)
if(!visy[i]&&t>slack[i])
t = slack[i];
for(i = ;i<=n1;i++)
if(visx[i])
lx[i]-=t;
for(i = ;i<=n2;i++)
if(visy[i])
ly[i]+=t;
else
slack[i]-=t;
//cout<<t<<endl;
}
//cout<<k<<endl;
}
double ans = ;
for(i = ;i<=n2;i++)
{
if(match[i]!=-)
ans+=g[match[i]][i];//cout<<g[match[i]][i]<<'?'<<endl;}
}
//cout<<ans<<'!'<<endl;
return ans;
} int main()
{
int t;
scanf("%d",&t);
int cas = ;
while(t--)
{
M(num,);
scanf("%d%d",&n,&m);
for(int i = ;i<n;i++)
for(int j = ;j<m;j++)
{
scanf("%lf",&num[i][j]);
}
double ans = ;
n1 = n2 = n;
for(int i = ;i<m;i+=n)
{
for(int j = ;j<n;j++)
{
for(int k = i;k<i+n;k++)
{
g[j+][k-i+] = num[j][k];
}
}
ans+=KM();
//cout<<ans<<endl;
}
printf("Case #%d: %.5f\n",cas++,ans);
}
return ;
}
Shanghai Regional Online Contest 1004的更多相关文章
- 2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017)
2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017) 全靠 wxh的博客 补完这套.wx ...
- 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2018)
layout: post title: 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 201 ...
- 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest
2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...
- 2017-2018 ACM-ICPC Latin American Regional Programming Contest PART (11/13)
$$2017-2018\ ACM-ICPC\ Latin\ American\ Regional\ Programming\ Contest$$ \(A.Arranging\ tiles\) \(B. ...
- UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVALive 7143 Room Assignment(组合数学+DP)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVALive 7141 BombX(离散化+线段树)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVALive 7139 Rotation(矩阵前缀和)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
随机推荐
- cantor三分集
值得一提的是,第一次听说cantor三分集是在数字电路课上,然而数电是我最不喜欢的课程之一...... 分形大都具有自相似.自仿射性质,所以cantor三分集用递归再合适不过了,本来不想用matlab ...
- 常见linux命令释义(第三天)
今天晚上看鸟哥的私房菜,边学边写笔记. 在linux中压缩大多是.tar, .tar.gz , .tgz, /gz, .bz2等. .gz 是通过gzip压缩的文件. .bz2 是通过bzip2压缩的 ...
- 高性能JavaScript笔记二(算法和流程控制、快速响应用户界面、Ajax)
循环 在javaScript中的四种循环中(for.for-in.while.do-while),只有for-in循环比其它几种明显要慢,另外三种速度区别不大 有一点需要注意的是,javascript ...
- 收集的一些jQuery (我平常用的少的,但确实挺有效果的)
禁用Jquery(动画)效果 jQuery.fx.off = true; 使用自己的 Bullets(这个有一丁点儿的小技巧) //这里是js代码 也就是给每个ul添加一个类名 然后给ul的子li前面 ...
- iOS - Availability.h
>for 'dispatch' application inner to begin note `#include <Availability.h>` These macros ar ...
- Low Power Consumption Design --- MCU Attention
20161008 note : I have a PCB board called 'A' where a piece of STM8L052C6 and a piece of CC1101 are ...
- 【转】七种常见阈值分割代码(Otsu、最大熵、迭代法、自适应阀值、手动、迭代法、基本全局阈值法)
http://blog.csdn.net/xw20084898/article/details/17564957 一.工具:VC+OpenCV 二.语言:C++ 三.原理 otsu法(最大类间方差法, ...
- audio patch(10.9.3) [2.6.1]
; Basic Block Input Regs: rax - Killed Regs: <nothing>0000000000048353 3D8419D411 ...
- SVM基本思想和对偶推导笔记-记录毕业论文1
快毕业啦~~记得上一篇论文利用JointBoost+CRF做手绘草图的分割项目在3月份完结后,6月份去实习,9月份也没怎么认真找工作就立刻回来赶论文(由于分割项目与人合作难以写入毕业论文),从9月到1 ...
- JQuery------获取<input type="file">中的文件内容
html <div class="File">添加附件</div><input id="upfile" name="up ...