POJ 2068 Nim 组合游戏
2014-11-21 10:45
253 查看
题目大意:有一堆石子,两伙人,围在一起坐,坐的顺序是ABABABAB。。。。每一个人最多能取a[i]个石子,取走最后一个石子的就输了。问谁能赢。
思路:朴素的组合游戏判定问题,这个题给了数据范围,可以进行记忆化搜索。f[i][j]为还剩下i个石子,到了第j个人的时候的状态,然后记忆化一下。
CODE:
思路:朴素的组合游戏判定问题,这个题给了数据范围,可以进行记忆化搜索。f[i][j]为还剩下i个石子,到了第j个人的时候的状态,然后记忆化一下。
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 10010 using namespace std; int cnt,total,src[30]; int f[MAX][30]; bool Judge(int last,int pos) { if(f[last][pos] != -1) return f[last][pos]; if(!last) return true; int next = (pos + 1 > cnt * 2) ? 1:pos + 1; for(int i = 1; i <= src[pos] && last - i >= 0; ++i) if(!Judge(last - i,next)) return f[last][pos] = 1; return f[last][pos] = 0; } int main() { while(scanf("%d",&cnt) && cnt) { scanf("%d",&total); memset(f,-1,sizeof(f)); for(int i = 1; i <= (cnt << 1); ++i) scanf("%d",&src[i]); printf("%d\n",Judge(total,1) ? 1:0); } return 0; }
相关文章推荐
- Poj 1067 取石子游戏(NIM,威佐夫博奕)
- 组合数学——Nim取子游戏
- POJ 2068 Nim(博弈+dp)
- 博弈之 Nim 游戏&poj 3537 Crosses and Crosses
- HDU 1536 S-Nim(组合游戏Nim)
- POJ 2068 NIM (博弈DP)
- poj 2068 Nim(博弈dp)
- 【POJ】【2068】Nim
- poj2068--Nim
- poj 2068 Nim 博弈论
- poj 2068 NIM (博弈DP)
- POJ 1704 Georgia and Bob (Nim游戏变形)
- 【poj 2068】Nim
- [原博客] POJ 2505 A multiplication game 组合游戏
- POJ-2068-Nim
- POJ 1704 Georgia and Bob (Nim游戏变形)
- poj_Nim_2068
- poj 2068 Nim 博弈论dp
- HDU1850博弈论_NIM游戏——POJ2975
- POJ 2348 Euclid's Game 组合游戏