poj 2068 Nim 博弈论dp
来源:互联网 发布:华雄深孔钻编程视频 编辑:程序博客网 时间:2024/05/20 20:19
题意:
给S个石子,2个队,每队n个人,每队轮流拿石子,每人能拿的最大石子数作为输入给出,问先拿的队必胜还是必败。
分析:
必败态的下个状态都是必胜态,必胜态的下个状态有必败态,状态明确了就能dp了,一开始定义的是dp[石子数][游戏经过步数],后来发现dp[石子数][选手编号]就可以了。
代码:
//poj 2068//sep9#include<iostream>using namespace std;int grundy[9000][24];int player[24];int n,S;int rec(int stone,int cur){if(grundy[stone][cur%(2*n)]!=-1)return grundy[stone][cur%(2*n)];if(stone==1)return grundy[stone][cur%(2*n)]=0;if(stone<=player[cur%(2*n)]+1)return grundy[stone][cur%(2*n)]=1;int ok=0;for(int k=1;k<=player[cur%(2*n)];++k)if(rec(stone-k,cur+1)==0){ok=1;break;}return grundy[stone][cur%(2*n)]=ok; }int main(){while(scanf("%d",&n)==1&&n){memset(grundy,-1,sizeof(grundy));scanf("%d",&S);for(int i=0;i<2*n;i+=2)scanf("%d%d",&player[i],&player[i+1]);printf("%d\n",rec(S,0));}return 0;}
0 0
- poj 2068 Nim 博弈论dp
- POJ 2068 Nim(博弈论+dfs)
- 【POJ 2975】 Nim 博弈论
- POJ 2975 Nim(博弈论)
- POJ 2068 NIM (博弈DP)
- poj 2068 NIM 博弈+dp
- poj 2068 NIM (博弈DP)
- POJ 2068 Nim(博弈+dp)
- POJ 2068 Nim 博弈DP
- POJ 2068 Nim <博弈dp>
- POJ 2960 S-Nim 【博弈论,SG函数】
- poj 2234 博弈论Nim取子游戏
- POJ 1704 Georgia and Bob(nim博弈论)
- POJ 2960 S-Nim 博弈论,SG函数
- POJ 2975 Nim题解---简单的博弈论
- poj 2068 Nim(博弈dp)
- 【bzoj 4347】 [POI2016]Nim z utrudnieniem - 博弈论 DP
- POJ-2960(S-Nim)——博弈论,SG函数
- URAL 1389 Roadworks
- 黑马程序员-----网络编程
- 【错误处理】CentOS命令登录MySQL时,报错ERROR 1045 (28000):
- IOS Android 手机助手原理以及源码(iTunesMobileDevice.dll 函数)
- CSS轮廓,突出元素
- poj 2068 Nim 博弈论dp
- SCU 4438 Censor (KMP)
- JavaScript跨域总结与解决办法
- python的timer带参数传递
- BNUoj 50401 Right turn 转向问题
- ccs框模型与可视化格式模型
- 关于APP中,广告栏实现目视循环播放的效果
- Linux<一>:Linux启动及登陆
- NOIP快速幂复习