您的位置:首页 > 其它

uva_10404_Bachet's Game

2012-11-09 14:18 447 查看
这道题居然卡了一天,自愧。
状态:dp[i]表示在数为i的时候先下的那个人是否输赢
状态转移:dp[i] 前的状态dp[j]能否到达dp[i],若能而且
dp[j] = 0, dp[i] = 1,则表示第n开始的时候第一人可以有必胜的把握
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define MAXVAL          11
#define MAXN            1000001

int dp[MAXN], val[MAXVAL], flag, m;

int sure_win(const int &n)
{
memset(dp, 0, sizeof(int)*(n+1)); dp[0] = 0;
for(int i = 0; i <= n; i ++) {
for(int j = 0; j < m; j ++) {
if( i < val[j] || dp[i] ) {
continue;
}
if( !dp[i-val[j]] ) {
dp[i] = 1;
}
}
}
return dp
;
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int n;
while( ~scanf("%d %d", &n, &m) ) {
for(int i = 0; i < m; i ++) {
scanf("%d", &val[i]);
}
if ( sure_win(n) ) {
printf("Stan wins\n"); continue;
}
printf("Ollie wins\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: