题意:给你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. git中的常用指令名及其意义

    add 添加新文件到 Git 代码仓库的索引中 $ git add filename mv 移动或重命名文件 $ git mv old-filename new-filename rm 从工作目录和 ...

  2. XAMPP的MYSQL无法启动

    昨天用各种方式试验MYSQL的数据库备份与恢复操作,恢复过程中,MYSQL就无法启动了. 提示如下: 22:59:43 [mysql] Attempting to start MySQL app... ...

  3. JScript_Test

    Hello SyntaxHighlighter function helloSyntaxHighlighter() { return "hi!"; } function hello ...

  4. 你需要知道的九大排序算法【Python实现】之基数排序

    八.基数排序 基本思想:基数排序(radix sort)属于"分配式排序"(distribution sort),又称"桶子法"(bucket sort)或bi ...

  5. CSS3: box-sizing 属性的简单认识

    定义和用法: box-sizing 属性允许您以特定的方式定义匹配某个区域的特定元素. 默认值:content-box; 继承性:无: css版本:css3 语法:box-sizing: conten ...

  6. AddForce给物体添加刚体效果并且脚本增加一个力(按空格实现)

    using UnityEngine; using System.Collections; public class CubeAddForce : MonoBehaviour { float hor,v ...

  7. String path = request.getContextPath();这段什么用

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

  8. resin安装

    1. 说明 Resin版本:resin-3.1.6 2. 安装jdk 安装jdk-1_5_0_09-windows-i586-p.exe程序到相应目录. (假设安装到D:\ jdk1.5.0_09) ...

  9. linux程序自启动和新建linux服务的方法

    1 linux创建自启动程序    自启动的两种方法,都经过自己测试.1.1 自启动程序方法1:    在etc/rc.local在里面加入/home/robin/code/autoruntest & ...

  10. Linq 学习(1) 概述

    本篇简单回顾C#语言集合操作的变化,通过与Linq对等的面向对象的语法来认识Linq.Linq是Language Integrated Query, 初识Linq感觉跟SQL Server的Tsql很 ...