您的位置:首页 > 其它

UVa 10404 - Bachet's Game

2013-06-16 10:25 453 查看
/*
DP: 假设可取石子数为1,3。
若总共1或3个石子,则先拿的人必胜。
若总共2、4个石子先拿的人必败。
若5个石子,则先拿的人取1个石子,则必胜
...
*/
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1000005;
const int MAXM = 15;
int n, m;
int A[MAXM];
int d[MAXN];

int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
while(scanf("%d%d", &n, &m) == 2) {
for(int i=0; i<m; i++) {
scanf("%d", &A[i]);
}
d[0] = 0;
for(int i=1; i<=n; i++) {
int found = 0;
for(int j=0; j<m; j++) {
if(i >= A[j] && !d[i-A[j]]) {
d[i] = 1;
found = 1;
break;
}
}
if(!found) d[i] = 0;
}
if(d
) printf("Stan wins\n");
else printf("Ollie wins\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: