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

    统一的数据获取 在WebForm时代,我们是怎么获取值的呢? HttpContext.Request.QueryString HttpContext.Request.Form HttpContext. ...

  2. 【Beta版本】冲刺-Day4

    队伍:606notconnected 会议时间:12月12日 目录 一.行与思 二.站立式会议图片 三.燃尽图 四.代码Check-in 一.行与思 张斯巍(433) 今日进展:协助队友完成界面的修改 ...

  3. 网络存储(三)之ISCSI搭建的入门

    搭建iscsi 我们就拿两台linux服务器来做吧, 服务器系统均为CentOs6.6 64位的,信息如下 IP 安装的软件 192.168.22.142 iscsi target端:scsi-tar ...

  4. angular评论星级指令

    地址: https://github.com/happen-zh/myStar 支持最大数,是否必填,回调,是否只读

  5. linux第一面

    随着Linux应用的扩展许多朋友开始接触Linux,根据学习Windwos的经验往往有一些茫然的感觉:不知从何处开始学起.作为一个 Linux系统管理员,我看了许多有关Linux的文档和书籍,并为学习 ...

  6. qt5.4

    rm -f libQt5Qml.so.5.4.0 libQt5Qml.so libQt5Qml.so.5 libQt5Qml.so.5.4g++ -Wl,-O1,--sort-common,--as- ...

  7. 介绍ping中的TTL是什么意思

    ping是icmp报文的一种应用.用来测试网络中各设备的连通性.在这几天的实验课上,我又用到了这个非常常用的命令,但是这次我发现了一些以前没有太注意的地方,那就是我在Ping不同的地址时所返回的TTL ...

  8. Java数据库——ResultSet接口

    使用SQL中的SELECT语句可以查询出数据库的全部结果,在JDBC的操作中数据库的所有查询记录将使用ResultSet进行接收,并使用ResultSet显示内容. 从user表中查询数据 //=== ...

  9. Wget命令下载、备份博客

    -np http://www.cnblogs.com/memory4young/p/ 参考资料: http://www.cnblogs.com/memory4young/p/wget-backup-b ...

  10. activity栈的关系

    android:intent flags 一.Activity和Task(栈)的关系 Task就像一个容器,而Activity就相当与填充这个容器的东西,第一个东西(Activity)则会处于最下面, ...