【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, ...
随机推荐
- 使用eBay API基本步骤介绍
要开始使用eBay API,需要如下基本步骤: 1. 注册开发帐号: https://developer.ebay.com/join/Default.aspx 2. 选择API类型: eB ...
- ORACLE 对用户密码做限制
1. 查看默认设置 2. PASSWORD_LIFE_TIME 60 --口令的生命周期,超过这段时间口令可能会自动过期,是否过期要看是否设定了PASSWORD_GRACE_TIME PASSWORD ...
- 解决Toad for Oracle显示乱码问题
1.查看一下数据库字符集: 使用下面语句:Select userenv('language') from dual;或者:Select name, value$ from props$;查看. 查看完 ...
- (转)一网打尽当下NoSQL类型、适用场景及使用公司
摘要:对比传统关系型数据库,NoSQL有着更为复杂的分类——键值.面向文档.列存储以及图数据库.这里就带你一览NoSQL各种类型的适用场景及一些知名公司的方案选择. 在过去几年,关系型数据库一直是数据 ...
- 反射-Reflect
1.得到一份Class(同一个类在JVM中只有一份字节码) 三种方式:类名.class, Class.forName("全限定名");, 对象.getClass(); 基本类型 i ...
- android ListView的介绍和优化
xml设计 <?xml version="1.0"?> -<RelativeLayout tools:context=".MainActivity&qu ...
- struts2中访问servlet API
Struts2中的Action没有与任何Servlet API耦合,,但对于WEB应用的控制器而言,不访问Servlet API几乎是不可能的,例如需要跟踪HTTP Session状态等.Struts ...
- C89 和 C99的标准比较
本文转载自: C89和C99标准比较 原文转载自: http://blog.programfan.com/article.asp?id=14051 http://blog.csdn.net/xgb ...
- 十个最常见的Java字符串问题
翻译自:Top 10 questions of Java Strings 1.怎样比较字符串?用”==”还是用equals()? 简单地说,”==”测试两个字符串的引用是否相同,equals()测试两 ...
- Android Studio添加jar包
1.先把jar包复制到项目的lib下,