Pitcher Rotation - POJ 3392 dp

Pitcher Rotation
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 543 Accepted: 138

Description

For professional baseball team managers, it is an important task to decide the starting pitcher for each game. In the information era, massive data has been collected in professional sports. The manager knows the winning percentage of each pitcher against each team. Unfortunately, when playing against a certain team you cannot always pick the pitcher with the highest winning percentage against that team because there is a rule saying that after pitching a game the pitcher has to rest for at least four days. There are n pitchers (5 ≤ n ≤ 100), m opponent teams (3 ≤ m ≤ 30), and there are g (3 ≤ g ≤ 200) games in a season, and the season lasts for g + 10 days. Furthermore, there is at most one game per day. You are given an m by n matrix P, where an element in PPij, denote the winning percentage of pitcher j against team i, and a list of g + 10 numbers, d1d2, …, dg + 10, to represent the schedule of the team, where di denotes the opponent team and di = 0 denotes that there is no game at the ith day of the season. Your task is to decide the starting pitcher for each game so that the expected number of winning game is maximized.

Input

The first line contains an integer t (1 ≤ t ≤ 5) indicating the number of teams that need your help. The data about these t teams follows. For each team, the first line contains the number of pitchers n, the number of opponent teams m, and the number of games in a season g. The next m lines contains the information about winning percentage of each pitcher against each team; the first line is p11p12, …, p1n, and the ith line is pi1pi2, …, pin, where each pij is a two-digit number (for example, 92 represents 0.92). The next g + 10 lines describe the schedule of the season, d1d2, …, dg + 10.

Output

The maximum value with exactly two digits past the decimal point of expected game won for these t teams in the order of their appearance in the input file, output the answer for each team in separated lines.

Sample Input

1
5 3 6
91 90 50 50 50
65 40 60 60 60
66 40 60 60 60
1
2
3
3
2
1
0
0
0
0
0
0
0
0
0
0

Sample Output

4.26

题意:你有n个队员,和m个敌人,共g+10天,每个人对每个敌人都有一个获胜的概率,一个人打一场比赛后需要休息4天,问你最后最大的获胜期望是多少。

思路:对于每个敌人,你只需要找出获胜概率最大的5个就够了。因为最多会有4个人休息。然后就是五维的dp。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

struct node
{
    int val,pos;
}em[110][110];
bool cmp(node a,node b)
{
    return a.val>b.val;
}
int dp[2][6][6][6][6];
int T,t,n,m,g,fight[300],vis[110],num[10],from,to,day,ans;
void dfs(int pos)
{
    if(pos==-1)
    {
        dp[to][num[1]][num[2]][num[3]][num[4]]=max(dp[to][num[1]][num[2]][num[3]][num[4]],
                    dp[from][num[0]][num[1]][num[2]][num[3]]+em[fight[day]][num[4]].val);
        return;
    }
    for(num[4-pos]=1;num[4-pos]<=5;num[4-pos]++)
    {
        if(vis[em[fight[day-pos]][num[4-pos]].pos]>0)
          continue;
        vis[em[fight[day-pos]][num[4-pos]].pos]++;
        dfs(pos-1);
        vis[em[fight[day-pos]][num[4-pos]].pos]--;
    }
}
int main()
{
    int i,j,k,a,b,c,d;
    scanf("%d",&T);
    for(t=1;t<=T;t++)
    {
        scanf("%d%d%d",&n,&m,&g);
        memset(em,0,sizeof(em));
        memset(fight,0,sizeof(fight));
        for(i=1;i<=m;i++)
           for(j=1;j<=n;j++)
           {
               scanf("%d",&em[i][j]);
               em[i][j].pos=j;
           }
        for(i=1;i<=m;i++)
           sort(em[i]+1,em[i]+1+n,cmp);
        n=min(n,5);
        for(i=11;i<=g+20;i++)
           scanf("%d",&fight[i]);
        memset(dp,0,sizeof(dp));
        vis[0]=-100;

        for(day=11;day<=g+20;day++)
        {
            if(day&1)
              from=0;
            else
              from=1;
            to=1^from;
            memset(dp[to],0,sizeof(dp[to]));
            dfs(4);
        }
        ans=0;
        for(a=0;a<=5;a++)
           for(b=0;b<=5;b++)
              for(c=0;c<=5;c++)
                 for(d=0;d<=5;d++)
                    ans=max(ans,dp[to][a][b][c][d]);
        printf("%.2f\n",0.01*ans);
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值