HDU 5045 Contest
2014-10-01 15:34
375 查看
Contest
Time Limit: 1000msMemory Limit: 65536KB
This problem will be judged on HDU. Original ID: 5045
64-bit integer IO format: %I64d Java class name: Main
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
1 2 3 0.6 0.3 0.4 0.3 0.7 0.9
Sample Output
Case #1: 2.20000
Source
2014 ACM/ICPC Asia Regional Shanghai Online解题:状压dp,费用流。网赛时,是用状压dp解的,现在写份费用流题解。最小费用流。。。。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <vector> #include <queue> #include <cstdlib> #include <string> #include <set> #include <stack> #define LL long long #define pii pair<int,int> #define INF 0x3f3f3f3f using namespace std; struct arc { int to,flow,next; double cost; arc(int x = 0,int y = 0,double z = 0,int nxt = -1) { to = x; flow = y; cost = z; next = nxt; } }; int head[30],tot,p[30]; arc e[1000]; bool in[30]; double d[30],pp[12][1010]; void add(int u,int v,int flow,double cost) { e[tot] = arc(v,flow,cost,head[u]); head[u] = tot++; e[tot] = arc(u,0,-cost,head[v]); head[v] = tot++; } bool spfa(int S,int T) { for(int i = 0; i < 30; i++) { p[i] = -1; d[i] = INF; in[i] = false; } d[S] = 0; queue<int>q; q.push(S); while(!q.empty()) { int u = q.front(); q.pop(); in[u] = false; for(int i = head[u]; ~i; i = e[i].next) { if(e[i].flow && d[e[i].to] > d[u] + e[i].cost) { d[e[i].to] = d[u] + e[i].cost; p[e[i].to] = i; if(!in[e[i].to]) { q.push(e[i].to); in[e[i].to] = true; } } } } return p[T] > -1; } double calc(int S,int T) { double tmp = 0.0; int mxV; while(spfa(S,T)) { mxV = INF; for(int i = p[T]; ~i; i = p[e[i^1].to]) mxV = min(mxV,e[i].flow); for(int i = p[T]; ~i; i = p[e[i^1].to]) { e[i].flow -= mxV; e[i^1].flow += mxV; tmp += e[i].cost*mxV; } } return tmp; } int main() { int t,n,m,cs = 1; scanf("%d",&t); while(t--){ scanf("%d %d",&n,&m); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) scanf("%lf",pp[i]+j); } double ans = 0; for(int i = 0; i < m; i += n){ tot = 0; memset(head,-1,sizeof(head)); for(int j = 1; j <= n; j++){ for(int k = 1; k <= n && i + k <= m; k++){ add(j,k+n,1,-pp[j][i+k]); } } for(int j = 1; j <= n; j++) add(0,j,1,0); for(int j = 1; j <= n && j+i <= m; j++) add(j+n,2*n+1,1,0); ans += -calc(0,2*n+1); } printf("Case #%d: %.5f\n",cs++,ans); } return 0; }
View Code
相关文章推荐
- hdu----(5045)Contest(数位dp)
- HDU 5045 Contest 期望+状压dp 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU - 5045 Contest(DP+状压)
- HDU 5045 Contest(DFS 回溯)
- hdu 5045——Contest
- HDU-5045 Contest(状压DP)
- HDU 5045 Contest(状压DP或费用流)
- Hdu 5045 Contest (2014 上海Online) (状态压缩dp)
- HDU 5045 Contest
- 【DP】 HDU 5045 Contest 状压
- hdu 5045 Contest(dp)
- hdu 5045 Contest
- 【DP】 HDU 5045 Contest 状压
- HDU 5045 Contest (2014上海网络赛)
- hdu 5045 Contest
- hdu 5045(上海网赛1004)Contest
- HDU_5045_Contest(状态压缩or最小费用最大流)
- hdu 5045 Contest 状态压缩dp
- [ACM] hdu 5045 Contest (减少国家Dp)
- hdu 5045 Contest 2014 ACM/ICPC Asia Regional Shanghai Online 网络流