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);
    }
}



内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值