10404-bachet ' s Game
Time limit:6.666 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_ problem&problem=1345
Game ~
Rule 1: A state is a must-lose state if and only if all subsequent successors are a must-fail state
Rule 2: A state is a winning state when and only if it has at least one successor is a must-lose state
Boundary: This problem 0 is a must-lose state
Train of thought: from the bottom up to push, don ' t you?
PS: Recursion will burst stack.
Complete code:
/*0.399s*/
#include <bits/stdc++.h>
using namespace std;
BOOL dp[1000005];
int a[11];
int main ()
{
int n, M, I, J;
BOOL Flag;
while (~SCANF ("%d%d", &n, &m))
{for
(i = 0; i < m; ++i)
scanf ("%d", &a[i]);
Sort (A, A + m);
for (i = 1; I <= n; ++i)
{
flag = false;
for (j = 0; J < m && I >= a[j]; ++j)
if (!dp[i-a[j])
{
flag = true;
break;
Dp[i] = flag;
}
Puts (Dp[n]? "Stan wins": "Ollie wins");
return 0;
}
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/