zoukankan      html  css  js  c++  java
  • HDU 5045 Contest

    Contest

    Time Limit: 1000ms
    Memory 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

     
    解题:状压dp,费用流。网赛时,是用状压dp解的,现在写份费用流题解。最小费用流。。。。
     
      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstring>
      4 #include <cmath>
      5 #include <algorithm>
      6 #include <climits>
      7 #include <vector>
      8 #include <queue>
      9 #include <cstdlib>
     10 #include <string>
     11 #include <set>
     12 #include <stack>
     13 #define LL long long
     14 #define pii pair<int,int>
     15 #define INF 0x3f3f3f3f
     16 using namespace std;
     17 struct arc {
     18     int to,flow,next;
     19     double cost;
     20     arc(int x = 0,int y = 0,double z = 0,int nxt = -1) {
     21         to = x;
     22         flow = y;
     23         cost = z;
     24         next = nxt;
     25     }
     26 };
     27 int head[30],tot,p[30];
     28 arc e[1000];
     29 bool in[30];
     30 double d[30],pp[12][1010];
     31 void add(int u,int v,int flow,double cost) {
     32     e[tot] = arc(v,flow,cost,head[u]);
     33     head[u] = tot++;
     34     e[tot] = arc(u,0,-cost,head[v]);
     35     head[v] = tot++;
     36 }
     37 bool spfa(int S,int T) {
     38     for(int i = 0; i < 30; i++) {
     39         p[i] = -1;
     40         d[i] = INF;
     41         in[i] = false;
     42     }
     43     d[S] = 0;
     44     queue<int>q;
     45     q.push(S);
     46     while(!q.empty()) {
     47         int u = q.front();
     48         q.pop();
     49         in[u] = false;
     50         for(int i = head[u]; ~i; i = e[i].next) {
     51             if(e[i].flow && d[e[i].to] > d[u] + e[i].cost) {
     52                 d[e[i].to] = d[u] + e[i].cost;
     53                 p[e[i].to] = i;
     54                 if(!in[e[i].to]) {
     55                     q.push(e[i].to);
     56                     in[e[i].to] = true;
     57                 }
     58             }
     59         }
     60     }
     61     return p[T] > -1;
     62 }
     63 
     64 double calc(int S,int T) {
     65     double tmp = 0.0;
     66     int mxV;
     67     while(spfa(S,T)) {
     68         mxV = INF;
     69         for(int i = p[T]; ~i; i = p[e[i^1].to])
     70             mxV = min(mxV,e[i].flow);
     71         for(int i = p[T]; ~i; i = p[e[i^1].to]) {
     72             e[i].flow -= mxV;
     73             e[i^1].flow += mxV;
     74             tmp += e[i].cost*mxV;
     75         }
     76     }
     77     return tmp;
     78 }
     79 int main() {
     80     int t,n,m,cs = 1;
     81     scanf("%d",&t);
     82     while(t--){
     83         scanf("%d %d",&n,&m);
     84         for(int i = 1; i <= n; i++){
     85             for(int j = 1; j <= m; j++)
     86                 scanf("%lf",pp[i]+j);
     87         }
     88         double ans = 0;
     89         for(int i = 0; i < m; i += n){
     90             tot = 0;
     91             memset(head,-1,sizeof(head));
     92             for(int j = 1; j <= n; j++){
     93                 for(int k = 1; k <= n && i + k <= m; k++){
     94                     add(j,k+n,1,-pp[j][i+k]);
     95                 }
     96             }
     97             for(int j = 1; j <= n; j++)
     98                 add(0,j,1,0);
     99             for(int j = 1; j <= n && j+i <= m; j++)
    100                 add(j+n,2*n+1,1,0);
    101             ans += -calc(0,2*n+1);
    102         }
    103         printf("Case #%d: %.5f
    ",cs++,ans);
    104     }
    105     return 0;
    106 }
    View Code
  • 相关阅读:
    C#获取IP信息
    获取百度地图按条件查找的信息
    react中如何实现一个按钮的动态隐藏和显示(有效和失效)
    es6 关于map和for of的区别有哪些?
    js 高级程序设计 第四章学习笔记
    ant design Table合并单元格合并单元格怎么用?
    React中如何实现模态框每次打开都是初始界面
    前端界面布局相关整理之2017
    待改善的代码整理
    cq三期备注说明
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4003309.html
Copyright © 2011-2022 走看看