题意:给你2n个人,两方各n个人,交叉坐,每个人可以取的石子有一个最大限制,总共有S颗石子,哪一方取了最后一颗石子就输了,问先取石子的这一方是否有必胜策略。

DP,dp[i][j]代表第i个人还有J个石子没有取得状态。记忆化搜索

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int dp[][],s,n,a[];
int dfs(int x,int f){
if (dp[x][f]!=-) return dp[x][f];
for (int i=;i<=a[x];i++){
int t=f-i,y;
if (t<) break;
if (x+>=*n) y=;else y=x+;
if (dfs(y,t)==) return dp[x][f]=;
}
return dp[x][f]=;
}
int main(){
while (scanf("%d",&n)&&n){
scanf("%d",&s);
for (int i=;i<*n;i++)
scanf("%d",&a[i]);
memset(dp,-,sizeof dp);
for (int i=;i<*n;i++) dp[i][]=;
int ans=dfs(,s);
if (ans) printf("1\n");
else printf("0\n");
}
}

poj2068--Nim的更多相关文章

  1. [POJ2068]Nim解题报告

    Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones ...

  2. 2018.09.25 poj2068 Nim(博弈论+dp)

    传送门 题意简述:m个石子,有两个队每队n个人循环取,每个人每次取石子有数量限制,取最后一块的输,问先手能否获胜. 博弈论+dp. 我们令f[i][j]f[i][j]f[i][j]表示当前第i个人取石 ...

  3. POJ2068 Nim 博弈论 dp

    http://poj.org/problem?id=2068 博弈论的动态规划,依然是根据必胜点和必输点的定义,才明白过来博弈论的dp和sg函数差不多完全是两个概念(前者包含后者),sg函数只是mex ...

  4. 博弈问题之SG函数博弈小结

    SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...

  5. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  6. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  7. 【poj2068】Nim

    Portal -->poj2068 Description ​  给你\(S\)个石子,有\(2n\)个人分成两队,编号为奇数的一队,编号为偶数的一队,\(2n\)个人按照编号从小到大的顺序拿石 ...

  8. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  10. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

随机推荐

  1. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 448  So ...

  2. VC++6.0注释快捷键设置

    在Qt Creator,eclipse等编辑器中,都默认有注释代码的快捷键:Ctrl + /. 注释快捷键在程序编程当中的作用相当明显,提高了编程效率.我在网上找到了一个在VC++6.0工具中添加注释 ...

  3. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  4. CoreText学习(一)Base Objects of Core Text

    最近要做一个读入Word,PDF格式等的文件并且加以编辑的程序,本来以为使用Text Kit结合Text View来打开doc文件是完全没问题的,结果用了各种方法打开要么是数据是nil,要么打开的文字 ...

  5. ubuntu下安装pdo扩展

    ubuntu下安装好LAMP后默认情况没有安装mysql_pdo扩展,以下是安装 步聚,在终端输入以下命令 1.pecl search pdo 2.sudo pecl install pdo 当出现E ...

  6. hibernate之关系映射上

    分别创建user,farm,user_general三张表 create table user( uuid bigint not null auto_increment, name ), age in ...

  7. HDU 1874-畅通project续(最短路Dijkstra+优先队列)

    畅通project续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 基本SQL语句练习(order by,group by,having)

    一.GROUP BY 和ORDER BY 1.使用Order by 进行排序,默认升序ASC,降序则使用DESC;(还可以这样:order by 1表示按第一列排序:order by 2 desc表示 ...

  9. ubuntu安装python3.5

    ubuntu14.04系统会自带python2.7,请不要卸载它.不同版本的Python可以共存在一个系统上. 卸载之后,桌面系统会被影响. (1)sudo add-apt-repository pp ...

  10. NumberSpinner( 数字微调) 组件

    本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个组件依赖于Numberbox(数值输入框)和 Spinner(微调)组件. 一. 加载方式//class 加载方式<i ...