标签:des style blog http io ar color os sp
题意为给出总石子数n,和m堆石子,两个人轮着取石子,每次只能从总石子中取m堆中的一堆的个数的石子,取走最后一个石子的胜。S先取,O后取。
用博弈的输赢观念+dp就可以了,由于记忆化搜索会爆栈,那就递推了,索性还好推……
不然就不会了……
#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; int dp[1000010]; int a[20]; int n,m; int main() { int i,j; while(cin>>n>>m) { for(i=0;i<m;i++) cin>>a[i]; for(i=0;i<=n;i++) { dp[i]=0; for(j=0;j<m;j++) if(i-a[j]>-1&&dp[i-a[j]]==0) { dp[i]=1; continue; } } if(dp[n]==1) cout<<"Stan wins"<<endl; else cout<<"Ollie wins"<<endl; } }
Time Limit:6666MS | Memory Limit:Unknown | 64bit IO Format:%lld & %llu |
Description
Here we consider a variation of this game. The number of stones that can be removed in a single move must be a member of a certain set of m numbers. Among the m numbers there is always 1 and thus the game never stalls.
20 3 1 3 8 21 3 1 3 8 22 3 1 3 8 23 3 1 3 8 1000000 10 1 23 38 11 7 5 4 8 3 13 999996 10 1 23 38 11 7 5 4 8 3 13
Stan wins Stan wins Ollie wins Stan wins Stan wins Ollie wins
Source
标签:des style blog http io ar color os sp
原文地址:http://blog.csdn.net/stl112514/article/details/41728205