Beans Game(博弈 | | DP)zoj 3057
2014-08-27 17:33
309 查看
Beans GameTime Limit: 5 Seconds Memory Limit: 32768 KB
There are three piles of beans. TT and DD pick any number of beans from any pile or the same number from any two piles by turns. Who get the last bean will win. TT and DD are very clever.
Input
Each test case contains of a single line containing 3 integers a b c, indicating the numbers of beans of these piles. It is assumed that 0 <= a,b,c <= 300 and a + b + c > 0.
Output
For each test case, output 1 if TT will win, ouput 0 if DD will win.
Sample Input
Sample Output
算法分析:
典型的威佐夫博弈问题是两堆,而此题为三堆。
原本以为这题是要找规律,但是找了一个小时没找到。百度解题报告,发现原来只要逆向推即可。采用递推比较快。
p[i][j][k] = 0表示状态为i,j,k时是必败态,p[i][j][k] = 1为必胜态。
从必败态往上推,能从必败态推出来的就是必胜态,赋值为1,如果是必胜点就不用往上推了。
p[i][j][k]初始化为必败点,如果该点不能从必败点转移过来,该点就是必败点。
由于必败点比较少所以可以节省时间。
[b][b]dp的做法正在补充。。。[/b]
There are three piles of beans. TT and DD pick any number of beans from any pile or the same number from any two piles by turns. Who get the last bean will win. TT and DD are very clever.
Input
Each test case contains of a single line containing 3 integers a b c, indicating the numbers of beans of these piles. It is assumed that 0 <= a,b,c <= 300 and a + b + c > 0.
Output
For each test case, output 1 if TT will win, ouput 0 if DD will win.
Sample Input
1 0 0 1 1 1 2 3 6
Sample Output
1 0 0 博弈题;相对于[b]取石子游戏[/b]那题多了一堆;(但,有一点不一样,就是范围!那么就简单多了) 题目大意:有三堆豆子a,b,c(a+b+c<=300)。TT和DD轮流从其中一堆拿走任意个豆子或从其中的两种拿走同样多的豆子,最后一个拿完的获胜。
算法分析:
典型的威佐夫博弈问题是两堆,而此题为三堆。
原本以为这题是要找规律,但是找了一个小时没找到。百度解题报告,发现原来只要逆向推即可。采用递推比较快。
p[i][j][k] = 0表示状态为i,j,k时是必败态,p[i][j][k] = 1为必胜态。
从必败态往上推,能从必败态推出来的就是必胜态,赋值为1,如果是必胜点就不用往上推了。
p[i][j][k]初始化为必败点,如果该点不能从必败点转移过来,该点就是必败点。
由于必败点比较少所以可以节省时间。
#include<stdio.h> #include<string.h> bool vis[305][305][305]; void fun() { int i,j,k; for(i=0;i<=300;i++) { for(j=0;j<=300;j++) { for(k=0;k<=300;k++) { if(vis[i][j][k]==0) { int p; for(p=i+1;p<=300;p++) vis[p][j][k]=1; for(p=j+1;p<=300;p++) vis[i][p][k]=1; for(p=k+1;p<=300;p++) vis[i][j][p]=1; for(p=1;p+i<=300&&p+j<=300;p++) vis[p+i][p+j][k]=1; for(p=1;p+j<=300&&p+k<=300;p++) vis[i][p+j][p+k]=1; for(p=1;p+i<=300&&p+k<=300;p++) vis[p+i][j][p+k]=1; } } } } } int main() { int a,b,c; memset(vis,0,sizeof(vis)); fun(); while(scanf("%d%d%d",&a,&b,&c)!=EOF) { printf("%d\n",vis[a][c]); } return 0; }
[b][b]dp的做法正在补充。。。[/b]
相关文章推荐
- Beans Game(博弈 | | DP)zoj 3057
- ZOJ 3057 Beans Game(博弈DP)
- ZOJ 3057 Beans Game 博弈DP
- ZOJ 3057 组合博弈 DP
- zoj 3057 博弈
- zoj 3057 Beans Game 博弈论
- ZOJ 3057 Beans Game 【DP+博弈】
- zoj3057 Beans Game---三维DP 博弈
- 博弈---ZOJ 3057 Beans Game(DP博弈)
- 博弈---ZOJ 3057 Beans Game(DP博弈)
- ZOJ 3822 Domination /2014牡丹江现场赛D题 (dp)
- JZOJ5233 【GDOI模拟8.5】概率博弈 树形dp
- ZOJ-3964 2017年浙大省赛G题博弈
- Codeforces 69D. Dot 博弈 dp
- ZOJ 2563 Long Dominoes(状态压缩+dp)
- zoj 3697(模拟+dp)
- ZOJ - 3469 Food Delivery(区间DP)
- ZOJ-3777 Problem Arrangement(dp状态压缩)
- ZOJ 3213 Beautiful Meadow(插头DP-一条路径最大值,不固定头尾)
- ZOJ 3802 Easy 2048 Again(压缩dp)