POJ-2068-Nim
2013-08-09 10:25
218 查看
题目是说有2*n个人坐在一起,分为2组(交叉坐即:1、3、5....是我方,2、4、6....是对方),共有s个石头,每次挨着取石头,石头不能超过当前人取最大的限制,若谁取到最后一个石头,那么就算失败。现在问我方是否能胜利,胜利输出1,失败输出0
思路:
用记忆化搜索就可以做了吧,建博弈树,
dp[i][j]表示为第i个人剩下j个石头的胜负情况
代码:
思路:
用记忆化搜索就可以做了吧,建博弈树,
dp[i][j]表示为第i个人剩下j个石头的胜负情况
代码:
#include<cstdio> #include<cstring> #include<iostream> using namespace std; const int maxn=8200; int dp[21][maxn],n,a[21],tot; bool DFS(int index,int res) { if(index==n+1) index=1; if(res==1) return false; if(res<=a[index]) return dp[index][res]=true;; if(dp[index][res]!=-1) return dp[index][res]; for(int i=1;i<=min(res,a[index]);i++) if(!DFS(index+1,res-i)) return dp[index][res]=true; return dp[index][res]=false; } int main() { while(scanf("%d",&n)&&n) { memset(dp,-1,sizeof(dp)); scanf("%d",&tot); n*=2; for(int i=1;i<=n;i++) scanf("%d",&a[i]); if(DFS(1,tot)) printf("1\n"); else printf("0\n"); } return 0; }
相关文章推荐
- POJ 2068 Nim 博弈DP
- poj 2068 NIM 博弈+dp
- poj 2068 Nim 博弈论
- poj 2068 NIM (博弈DP)
- POJ 2068 Nim(博弈+dp)
- POJ 2068 Nim (博弈和DP本是一家=-=)
- poj 2068 Nim
- poj_Nim_2068
- poj 2068 Nim 博弈论dp
- poj2068--Nim
- Nim(poj 2068)
- POJ 2068 Nim (记忆化搜索+组合博弈)
- dp博弈______Nim( poj 2068 )
- POJ 2068 Nim (记忆化搜索+组合博弈)
- poj 2068 Nim(博弈dp)
- POJ 2068 Nim 笔记
- POJ 2068 Nim (记忆化搜索+组合博弈)
- POJ 2068 Nim 组合游戏
- POJ 2068 Nim (记忆化搜索+组合博弈)
- 【poj 2068】Nim