如果d[i]是必胜态,那么d[i + V[j]]一定是必败态,反之亦然。
用d[i]代表棋子为i个是否为必胜态。
边界条件是d[i] = 1;
14139291 | 10404 | Bachet‘s Game | Accepted | C++ | 0.662 | 2014-09-03 09:44:48 |
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<list> #include<cmath> #include<string> #include<sstream> #include<ctime> using namespace std; #define _PI acos(-1.0) #define esp 1e-9 typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pill; /*===========================================*/ #define MAX_SIZE 1000000 + 10 #define INF (1 << 20) const int MAXD = 10 + 5; int dp[MAX_SIZE]; int main(){ int T; int arr[MAXD]; while(scanf("%d",&T) != EOF){ memset(dp,0,(T + 1)*sizeof(dp[0])); int n; scanf("%d",&n); for(int i = 0 ; i < n ; i++) scanf("%d",&arr[i]); dp[1] = 1; for(int i = 0 ; i <= T ; i++) for(int j = 0 ; j < n ; j++) if(i + arr[j] <= T && !dp[i]){ dp[i + arr[j]] = 1; } if(dp[T]) printf("Stan wins\n"); else printf("Ollie wins\n"); } return 0; }
【UVA】10404-Bachet's Game(动态规划)
时间: 2024-10-29 19:05:32