【POJ】【2068】Nim
博弈论/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的更多相关文章
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- 【POJ 1459 power network】
不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...
- 【POJ 2728 Desert King】
Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...
- 【POJ 2976 Dropping tests】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...
- 【POJ 3080 Blue Jeans】
Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...
- 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)
1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- 【POJ 2823 Sliding Window】 单调队列
题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...
- 【POJ 2406 Power Strings】
Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...
- 【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, ...
随机推荐
- 搭建Cocos2d-JS开发环境
使用Cocos2d-JS引擎开发游戏,主要的程序代码是JavaScript语言,因此,凡是能够开发JavaScript语言工具都适用于Cocos2d-JS游戏开发.本书我们推荐WebStorm和Coc ...
- C#时间格式 tostring、toshortdatestring、toshorttimestring
在c#语言中的时间处理有几种方式: 首先获取当前时间:var date=new DateTime.Now; date.ToString()----2111-1-20 11:44:47 date.ToS ...
- UI2_NSUserDefaults
// // ViewController.m // UI2_NSUserDefaults // // Created by zhangxueming on 15/7/8. // Copyright ( ...
- GForms展现服务云开发平台
GForms完全基于开放标准,使用XForms作为面向服务的架构简单易用的前端,帮助用户跨多个行业加速数据整合.GForms提供可视化设计器,实现展现服务开发中数据与模型完全分离,加快开发速度快速投入 ...
- DOM结构学习备忘
1.动态修改页面title: document.title="项目启动33"; 2.IE中打开UTF-8编码的网页中title显示空白页的问题 3.
- 《asp.net mvc实战》笔记
对于大部分复杂的项目来说,可能不会在Models文件夹中放置你的模型.一般来说,最好的方法是将你的领域模型放在独立的项目中.这样其他应用程序可以在使用该项目而不必依赖于你的MVC应用程序.我们建议你只 ...
- JS函数式编程【译】第二章总结
- JavaScript选项卡
实现js选项卡 html的代码如下: <div class="tabdiv"> <ul class="tabs" id="oTab& ...
- 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m
给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后 ...
- Tomcat启动超时
当启动tomcat时候出现 Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the s ...