/**
* 博弈和dp结合
* 首先有博弈论的一些基础:
* 必胜点: 选手必胜的点,下一步要么停止,要么必然走到必败点。(因为都是以最优策略博弈的)
* 必败点: 选手必败的店,下一步要么停止,要么必然走到必胜点。
* 所以这题在结合下dp,题给出的数组是一次可以选取的可能情况,所以这些点都是
* 必胜点,标记好必胜点后,再从2到num遍历一遍,假设现在选手在点i上,还没移动,
* 再枚举所有可能移动的点看能否移动到必败点,如果能,这就是个必胜点,不能则必败。
* 这题dp也是很容易想的。。
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#define INF 0x7fffffff
#define MAXS 1000001
#define LL long long
using namespace std;
int nums[MAXS], num, n, dp[MAXS];
void judge(int x) {
for(int i = 0; i < n && nums[i] < x; i ++) {
if(dp[x - nums[i]] == -1) {
dp[x] = 1;
return ;
}
}
dp[x] = -1;
}
void dpf() {
for(int i = 2; i <= num; i ++) {
if(dp[i] == 0) {
judge(i);
}
}
}
int main()
{
while(scanf("%d", &num) != EOF) {
memset(dp, 0, sizeof(dp));
scanf("%d", &n);
for(int i = 0; i < n; i ++) {
scanf("%d", &nums[i]);
dp[nums[i]] = 1;
}
sort(nums, nums + n);
dpf();
if(dp[num] == 1) printf("Stan wins\n");
else printf("Ollie wins\n");
}
return 0;
}
UVa 10404 - Bachet's Game 博弈+动态规划
最新推荐文章于 2020-01-17 17:44:54 发布