UVALive 6840Sweet War (博弈dp)
来源:互联网 发布:汉高薪资待遇 知乎 编辑:程序博客网 时间:2024/06/06 07:18
题意:
有一个栈,栈中有
n(n≤150) 个糖果,每个糖果有两种属性ai(ai<=109) 和bi 且∑ni−1bi<=150 。现在有两个人玩游戏,两人轮流操作,每次有两种操作:
1.跳过这次操作,但是总能量减少1 。(两人刚开始的能量分别为A,B(A,B≤109) ,且任意时刻能量不能小于0 )
2.取走栈顶的糖果,获得bi 分,且能量增加ai
游戏一直进行到栈中没有糖果为止,问:如果两人都足够聪明,他们各获得多少分。
分析:
我选择跳过对面也可以选择跳过,所以最后有跳过权限的只是能量高的,即能量的差值是有意义的
数据范围分值总和小于等于150,就是给我们提示,把分值开到状态去
考虑dp[i][j]:=i→n 的游戏, 获得j 美味度,最少需要先手与后手的能量差值
设sum=∑nk=isi
转移考虑
先手取,对于后手而言获得的美味度必然≤sum−j
那么对于所有的k>sum−j , 必然满足−(A−B)=−(dp[i][j]+r[i])<dp[i+1][k]
化简得dp[i][j]=max{−dp[i+1][k]−r[i]+1}
先手不取, 那么状态应该由k≥j 转移来, 因为多的可以获得, 那么至多需要那么多差值
那么dp[i][j]−1−r[i]>=dp[i+1][k] , 且dp[i][j]>=1
化简得dp[i][j]=min{max(dp[i+1][k]+1+r[i],1)}
代码:
//// Created by TaoSama on 2015-12-05// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;typedef long long LL;const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;int n, A, B;int r[155], s[155];LL f[155][155];void getMax(LL &x, LL y) { if(y > x) x = y;}void getMin(LL &x, LL y) { if(y < x) x = y;}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(scanf("%d%d%d", &n, &A, &B) == 3) { for(int i = 1; i <= n; ++i) scanf("%d%d", r + i, s + i); memset(f, 0x3f, sizeof f); f[n][s[n]] = -INFLL; int sum = s[n]; for(int i = n - 1; i; --i) { sum += s[i]; for(int j = sum; j >= s[i]; --j) { f[i][j] = -INFLL; for(int k = sum - j + 1; k <= sum; ++k) getMax(f[i][j], -f[i + 1][k] - r[i] + 1); for(int k = j; k <= sum; ++k) getMin(f[i][j], max(f[i + 1][k] + r[i] + 1, 1LL)); } } for(int i = sum; ~i; --i) { if(f[1][i] <= A - B) { printf("%d %d\n", i, sum - i); break; } } } return 0;}
0 0
- UVALive 6840Sweet War (博弈dp)
- UVALive 5760 Alice and Bob(博弈+记忆化dp or 找规律)
- UVALIVE 3516(DP)
- UVALive 6913 I Want That Cake 博弈dp
- UVA 10497 - Sweet Child Makes Trouble(DP+高精度)
- UVALive 6430 Points(dp)
- UVALive 6848Fishing(dp)
- UVALive 7365 Composition (DP)
- UVALive 3305 Tour(DP)
- uvalive(NIM博弈)
- UVALive 3695 (博弈 bfs)
- hdu-4597 (博弈DP)
- POJ 1085 Triangle War(博弈,極大極小搜索+alpha_beta剪枝)
- HDU 6139 Galaxy at War(坑题+阶梯博弈)
- UVALive 4625 Garlands(二分答案 + DP)
- UVALive 3305Tour(双调DP)
- UVALive 3608 Period(二分答案+DP)
- UVALive 2221 Frontier(计算几何 + DP)
- UVALive 6834Shopping (贪心)
- UVALive 6832Bit String Reordering (模拟)
- UVALive 6833Miscalculation (模拟)
- UVALive 6837There is No Alternative (MST + LCA)
- UVALive 6838Flipping Parentheses (线段树)
- UVALive 6840Sweet War (博弈dp)
- Angular JS 学习笔记四
- 电子或通信领域当前的主流技术及其社会需求调查
- Angular JS 学习笔记五
- 从零开始学c语言教程
- Mac 下 破解 sublime text 2 方法详解
- python核心编程-map函数
- excel排版:人工定制列宽时部分列宽参数
- python核心编程-map处理多个序列