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 ...
随机推荐
- webbench详解
安装 mkdir -p /usr/local/man/man1 yum install ctags -y tar zxvf webbench-1.5.tar.gzcd webbench-1.5make ...
- Autofac的高级使用——Autofac.2.6.3.862
Autofac的高级使用——Autofac.2.6.3.862 目录(?)[-] 使用代码方式进行组件注册依赖服务类和组件类 使用配置文件进行组件注册不需要依赖 定义配置文件 读取config配置文件 ...
- K米测试
K米评测 ------K米IOS4.3.0体验之旅 第一部分 :调研,评测 第一次上手体验: 像大多数同学一样,这也是我第一次使用k米这一类型的ktv点歌软件.我算是比较经常接触唱k的人,身边的朋友 ...
- 捉襟见肘之自定义自拍相机AVFoundation
因为上篇的问题的,我搜索到解决方法: http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-ima ...
- 捉襟见肘之TableView的手势(删除、编辑等)与转场动画手势冲突
在使用PresentModel的方式进行转场动画时,出现UIPercentDrivenInteractiveTransition和 UITableView的自带手势冲突,问题需要总结,今天系统复习和总 ...
- UVA3026Period(最短循环节)
题目链接 题意: 给定长度为n的字符串s,求他的每个前缀的最短循环节 分析: kmp预处理 next[]数组,然后对于 前 i 个字符,如果 next[i] > 0 && i % ...
- UVA11987Almost Union-Find(并查集删除节点)
题目链接 题意:n个数(即1-n)和m个操作: 1表示把x和y合并,2表示把x移到y集合里面,3表示统计x集合的元素个数 1,3好说,关键是2操作,可以先把2删除掉,删除的操作可以找一个其他的数字来取 ...
- the setting of serial port in the SecureCRT
set echo(display characters which are sent) Line wrap : press 'enter' to send '\r'(0x0D), go ...
- BZOJ4446: [Scoi2015]小凸玩密室
用ui,j表示走完i的子树后走到i的深度为j的祖先的兄弟的最小代价: 用vi,j表示走完i的子树后走到i的深度为j的祖先的最小代价,用u算出v. 枚举起点,计算答案. #include<bits ...
- winndows7、office2013 激活信息还原
windows7激活信息还原 1.现在“计算机”,右键中的“管理”中的“服务”中禁止Software Protection 2.还原路径C:\Windows\ServiceProfiles\Netwo ...