hdu 6199 沈阳网络赛---gems gems gems(DP)
2018-06-17 21:56:31来源:未知 阅读 ()
题目链接
They place the gems in a row and decide to take turns to take gems from left to right.
Alice goes first and takes 1 or 2 gems from the left. After that, on each turn a player can take k or k+1 gems if the other player takes k gems in the previous turn. The game ends when there are no gems left or the current player can't take k or k+1 gems.
Your task is to determine the difference between the total value of gems Alice took and Bob took. Assume both players play optimally. Alice wants to maximize the difference while Bob wants to minimize it.
For each test case:
the first line contains a numbers n (1≤n≤20000);
the second line contains n numbers: V1,V2…Vn. (−100000≤Vi≤100000)
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; const int N=20005; const int M=203; int sum[N]; int dp[M][2][205]; int main() { int T; cin>>T; while(T--) { sum[0]=0; memset(dp,0,sizeof(dp)); int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&sum[i]),sum[i]+=sum[i-1]; for(int i=n;i>=1;i--) { for(int j=1;j<M;j++) { if(i+j-1>n) break; int tmp=sum[i+j-1]-sum[i-1], t; if(i+j+j<=n) t=min(dp[(i+j)%M][1][j],dp[(i+j)%M][1][j+1]); else if(i+j+j-1<=n) t=dp[(i+j)%M][1][j]; else t=0; dp[i%M][0][j]=tmp+t; if(i+j+j<=n) t=max(dp[(i+j)%M][0][j],dp[(i+j)%M][0][j+1]); else if(i+j+j-1<=n) t=dp[(i+j)%M][0][j]; else t=0; dp[i%M][1][j]=t-tmp; } } int ans; if(n>=2) ans=max(dp[1][0][1],dp[1][0][2]); else ans=dp[1][0][1]; printf("%d\n",ans); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash