Topic Link: Click to open the link
In the DP topic brush, look like game on the water passed.
Test instructions: N items, two people take turns, the number of each fetch must be a set of S (the set must contain 1) in a number, and finally can not be picked to lose (that is, take away the last item wins).
Idea: recursion. Set W[i] for the status of I items, W[i]=1 represents the initiator win, W[i]=0 represents the initiator will be defeated. You can know w[1]=1, and recursion generates all States.
It can be known that for a state, if his successor will fail, then the state is the winning state, if all subsequent to the state is a winning state, then the state is a must.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1000002#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long longusing na Mespace std;int N,m,s[12];bool w[maxn];void Solve () {memset (w,0,sizeof (w)); w[1]=1;for (int i=2;i<=n;i++) {w[i]=0; for (int j=0;j<m&&i-s[j]>=0;j++) {if (!w[i-s[j]) {w[i]=1;break;}}} if (W[n]) puts ("Stan wins"), Else puts ("Ollie wins");} int main () {while (~SCANF ("%d", &n)) {scanf ("%d", &m), and for (int i=0;i<m;i++) scanf ("%d", s+i); sort (s,s+m); Solve ();} return 0;}
Uva 10404-bachet ' s game (game)