博弈论/DP

  这是Nim?这不是巴什博奕的变形吗……

  我也不会捉啊,不过一看最多只有20个人,每人最多拿16个石子,总共只有8196-1个石子,范围好像挺小的,嗯目测暴力可做。

  so,记忆化搜索直接水过去了……

  出口应该很好判断:当前只有一个石子的时候输,石子数<=m[i]+1则赢(保证拿完后只给对方留一个)

 Source Code
Problem: User: sdfzyhy
Memory: 1416K Time: 32MS
Language: G++ Result: Accepted Source Code //POJ 1000
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std; int getint(){
int r=,c=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if (ch=='-') c=-;
for(;isdigit(ch);ch=getchar()) r=r*+ch-'';
return r*c;
}
const int N=,INF=~0u>>;
const double eps=1e-;
/******************template***********************/
#define debug
int n,m,a[];
bool vis[][],dp[][];
bool f(int x,int y){
if (vis[x][y]) return dp[x][y];
vis[x][y]=;
if (y==) return dp[x][y]=;
if (y<=a[x]+) return dp[x][y]=; int next;
if (x==n*) next=;
else next=x+;
F(i,,a[x]) if (f(next,y-i)==) return dp[x][y]=;
return dp[x][y]=;
} int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
while(scanf("%d",&n)!=EOF && n){
m=getint();
F(i,,n<<) a[i]=getint();
memset(vis,,sizeof vis);
memset(dp,,sizeof (dp));
printf("%d\n",f(,m));
// F(i,1,n<<1) F(j,1,m) printf("f(%d,%d)=%d\n",i,j,dp[i][j]);
}
return ;
}

【POJ】【2068】Nim的更多相关文章

  1. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  2. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  3. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  4. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  5. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  8. 【POJ 2823 Sliding Window】 单调队列

    题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...

  9. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

  10. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

随机推荐

  1. LAMP+Proftpd+数据迁移

    on Centos 6.5 64bit minimal 安装mysql [root@ftp ~]# yum install -y mysql mysql-server mysql-devel  --安 ...

  2. Cocos2d-JS键盘事件

    Cocos2d-JS中的键盘事件与触摸事件不同,它没有空间方面信息.键盘事件不仅可以响应键盘,还可以响应设备的菜单.键盘事件是EventKeyboard,对应的键盘事件监听器(cc.EventList ...

  3. JavaScript知识思维导图

    知识点:(图片为网络转载,谢谢分享.) JavaScript 变量 JavaScript 数据类型 JavaScript 字符串函数 Javascript 运算符 JavaScript 流程控制 Ja ...

  4. 15个web前端的美轮美奂的 jQuery 图片特效

    jQuery是一个非常优秀的 JavaScript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,jQuery 最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入各种 ...

  5. The-ith-Element

    Brief: the-ith-element,given a array A with n element , return the i-th element of A.  A(n,i) this p ...

  6. SSH 正向/反向代理小记

    上周因为玩耍Minecraft的原因,折腾了下ssh的正向.反向代理,不得不说,科技改变命运..了解了基础的用法之后,很多跨域的事情都可以通过代理解决,而且只需要ssh帐号权限即可. 那么就简单来介绍 ...

  7. 【转】使用Memcached提高.NET应用程序的性能

    在应用程序运行的过程中总会有一些经常需要访问并且变化不频繁的数据,如果每次获取这些数据都需要从数据库或者外部文件系统中去读取,性能肯定会受到影响,所以通常的做法就是将这部分数据缓存起来,只要数据没有发 ...

  8. 转:JAVA中this用法小结

    转:http://blog.sina.com.cn/s/blog_6a6badc90100t8hm.html#SinaEditor_Temp_FontName Java关键字this只能用于方法方法体 ...

  9. C#操作Excel基本操作

    /// using Microsoft.Office.Core; using Microsoft.Office.Interop.Excel; using System.IO; using System ...

  10. 关于LINQ一个简单例子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...