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的更多相关文章

  1. 2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017)

    2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017) 全靠 wxh的博客 补完这套.wx ...

  2. 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 ...

  3. 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest

    2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...

  4. 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. ...

  5. 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 ...

  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 ...

  7. UVALive 7141 BombX(离散化+线段树)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  8. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  9. UVALive 7139 Rotation(矩阵前缀和)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

随机推荐

  1. php常用函数(持续更新)

    每一种编程语言在用的过程中都会发现有时候要一种特定需求的功能函数,结果没有内置这样的函数,这个时候就需要自己根据已有函数编写尽可能简单的函数,下面是我在做php相关工作时积累下的函数,会持续更新,您要 ...

  2. Load Average

    在Linux系统下面,有很多的命令可以查看系统的负载情况:比如top,uptime,w,示例如下: [wenchao.ren@l-cmsweb1.ops.cn1 ~]$ w 18:39:10 up 7 ...

  3. 重温布局(display)

    无聊,从新复习了一遍,基础布局,记录一下,避免忘了. 首先说一下 Css文件前缀 Firefox:-moz-box-shadow Safari:-webkit-box-shadow Opera:-o- ...

  4. centos7安装mplayer 错误集锦

    (1)在 linux下运行程序时,发现了error while loading shared libraries这种错误,一时间不知道解决办法,在网上搜索,终于解决了:./tests: error w ...

  5. CF 214B Hometask(想法题)

    题目链接: 传送门 Hometask Time Limit: 2 seconds     Memory Limit: 256 megabytes Description Furik loves mat ...

  6. javascript 代码可读性

    可读性的大部分内容都是和代码缩进相关的,必须保证代码有良好的格式.可读性的另一方面就是注释,一般而言,有如下一些地方需要进行注释 1.1.1 函数和方法 每个函数或方法都应该包含一个注释,描述其目的和 ...

  7. 【百度百科】对焦Focus

    词语解释 duìjiāo [focusing] 指使用照相机时调整好焦点距离 对焦也叫对光.聚焦.通过照相机对焦机构变动物距和相距的位置,使被拍物成像清晰的过程就是对焦. 自动对焦 传统相机,采取一种 ...

  8. css012 css布局简介

    css012  css布局简介 一.    网页布局的类型 网页布局的类型 1.固定宽度 2.流式 3.相应式web设计 二.    如何进行css布局 1.强大的<div>标签 网页的h ...

  9. SQL Server Transact-SQL 编程

    T-SQL语句用于管理SQL Server数据库引擎实例,创建和管理数据库对象,以及查询.插入.修改和删除数据. Ø 变量 . 局部变量(Local Variable) 局部变量是用户可以自定义的变量 ...

  10. C#创建用户控件 - IPv4地址输入框

    根据网上的改写:http://blog.csdn.net/jhqin/article/details/5823363 控件属性: Text:获取或设置string类型的IP地址 Value:获取或设置 ...