UVA 1379 Pitcher Rotation
来源:互联网 发布:防蹭网软件怎么用 编辑:程序博客网 时间:2024/04/30 19:30
题目链接:http://acm.hust.edu.cn/vjudge/problem/41556
题意:有g+10场比赛,每天一场,每场都会对应一个对手。你有n个投手,每人一场比赛结束后都要休息四天,给出n个人对应m个对手的n*m胜率矩阵。求胜率的最大期望。
思路:每个人5天可以一轮换,所以说对于某个对手来讲,就派胜率前五的投手去对战即可。dp[i][a][b][c][d]表示第i天派d出赛,前三天分别是a,b,c的最大获胜期望。
0表示休息。枚举会麻烦一下而已,转移并不难。空间可以用滚动数组优化一下。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod 100000007int dp[2][6][6][6][6]; //滚动数组int k[250];int n,m,g;int a[109][109];vector<int> S[109];struct node{ int v;int pos;}b[109];bool cmp( node x , node y ){ return x.v > y.v;}void init(){ cin>>n>>m>>g; S[0].clear(); S[0].push_back(0); rep(i,1,m) { rep(j,1,n) { scanf("%d",&a[i][j]); b[j].pos = j; b[j].v = a[i][j]; } sort(b+1,b+1+n,cmp); S[i].clear(); // i 表示对手编号为i时,S[i]里面存的投手编号 rep(j,1,5) S[i].push_back( b[j].pos ); } rep(i,1,g+10) cin>>k[i]; //比赛序列}void solve(){ Clean(dp,-1); dp[0][0][0][0][0] = 0; int last = 0 , now = 1; int ta,tb,tc,td; rep(i,1,g+10) { Clean(dp[now],-1); ta = i>=2?k[i-1]:0; tb = i>=3?k[i-2]:0; tc = i>=4?k[i-3]:0; td = i>=5?k[i-4]:0; if ( k[i] != 0 ) //如果当天有比赛 { for( int x = 0; x < (int)S[ k[i] ].size();x++ ) //枚举当天出赛的人 for( int t1 = 0; t1 < (int)S[ta].size(); t1++ ) //枚举前一天的 { if ( S[ta][t1] == S[k[i]][x] ) continue; for( int t2 = 0; t2 < (int)S[tb].size(); t2++ ) //枚举前两天的 { if ( S[tb][t2] == S[k[i]][x] ) continue; for( int t3 = 0; t3 < (int)S[tc].size(); t3++ ) //枚举前三天的 { if ( S[tc][t3] == S[k[i]][x] ) continue; for( int t4 = 0; t4 < (int)S[td].size(); t4++ ) //枚举前四天的 { if ( S[td][t4] == S[k[i]][x] ) continue; if ( dp[last][t4][t3][t2][t1] == -1 ) continue; //上一个状态求过 可以更新当前状态 dp[now][t3][t2][t1][x] = max( dp[now][t3][t2][t1][x] , dp[last][t4][t3][t2][t1] + a[ k[i] ][ S[k[i]][x] ] ); } } } } } else { for( int t1 = 0; t1 < 5; t1++ ) for( int t2 = 0; t2 < 5; t2++ ) for( int t3 = 0; t3 < 5; t3++ ) for( int t4 = 0; t4 < 5; t4++ ) if ( dp[last][t4][t3][t2][t1] != -1 ) dp[now][t3][t2][t1][0] = max( dp[now][t3][t2][t1][0] , dp[last][t4][t3][t2][t1] ); } now ^= 1; last ^= 1; } int ans = 0; rep(i,0,4) rep(j,0,4) rep(k,0,4) rep(l,0,4) ans = max( ans , dp[last][i][j][k][l] ); printf("%0.2f\n",ans/100.0);}int main(){ int T; cin>>T; while(T--) { init(); solve(); } return 0;}
0 0
- UVA 1379 Pitcher Rotation
- UVA 1379 Pitcher Rotation
- uva 1379 - Pitcher Rotation(dp)
- UVA 1379 - Pitcher Rotation(DP + 贪心)
- UVALive 3679 Pitcher Rotation
- Pitcher Rotation - POJ 3392 dp
- *(中等)动态规划 HOJ 2508 Pitcher Rotation
- UVALive 3679 Pitcher Rotation(DP)
- UVA Multiplying by Rotation
- The Rotation Game UVA
- The Rotation Game (UVA
- The Rotation Game UVA
- The Rotation Game UVA
- uva 550 - Multiplying by Rotation
- Uva 550 - Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- UVa 550 Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- HTML5-复选框
- HttpModule的认识
- css布局:圣杯布局
- day11_python多线程基础
- st表
- UVA 1379 Pitcher Rotation
- 小技巧小经验之-----居中
- Arcgis插值方法简介
- C++ 硬件信息 获取CPU序列号
- Win7实现双ip设置
- mysql优化查询
- Android开发心得整理
- 前端之路
- ReentrantLock(重入锁)以及公平性