There are three piles of beans. TT and DD pick any number of beans from any pile or the same number from any two piles by turns. Who get the last bean will win. TT and DD are very clever.
Input
Each test case contains of a single line containing 3 integers a b c, indicating the numbers of beans of these piles. It is assumed that 0 <= a,b,c <= 300 and a + b + c > 0.
Output
For each test case, output 1 if TT will win, ouput 0 if DD will win.
Sample Input
1 0 0 1 1 1 2 3 6
Sample Output
1 0 0
本想找什么归律什么,但这题好卡时间和内存,没想到直接这样打表就可以了!
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define M 301 bool dp[M][M][M]={0}; void init(){ int i,j,k,a,b,c; for(i=0;i<M;i++) for(j=0;j<M;j++) for(k=0;k<M;k++) if(!dp[i][j][k]){ for(a=1;i+a<M;a++) dp[i+a][j][k]=1; for(a=1;j+a<M;a++) dp[i][j+a][k]=1; for(a=1;k+a<M;a++) dp[i][j][k+a]=1; for(a=1;i+a<M&&j+a<M;a++) dp[i+a][j+a][k]=1; for(a=1;j+a<M&&k+a<M;a++) dp[i][j+a][k+a]=1; for(a=1;i+a<M&&k+a<M;a++) dp[i+a][j][k+a]=1; } } int main() { int a,b,c; init(); while(scanf("%d%d%d",&a,&b,&c)!=EOF){ printf("%d\n",dp[a][b][c]); } return 0; }