【ZOJ - 3057】Beans Game (博弈dp)

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

思路:

博弈dp,把所有状态的是否能赢提前求出来。必败态只能到必胜态,所以枚举每一个必败态后的每一个点,都标记为必胜态。

注意这道题数组不能开Int类型要开bool,要不会一直段错误。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
#define mod (19961993)
using namespace std;
typedef long long ll;
bool dp[302][302][302]={0};
//博弈dp
void init()
{
	for(int i=0;i<=300;i++)
	for(int j=0;j<=300;j++)
	for(int k=0;k<=300;k++)
	{
		if(!dp[i][j][k])
		{
			for(int t=1;t+i<=300;t++)//每次至少选一个  
			dp[t+i][j][k]=1;
			for(int t=1;t+j<=300;t++)
			dp[i][t+j][k]=1;
			for(int t=1;t+k<=300;t++)
			dp[i][j][t+k]=1;
			for(int t=1;t+i<=300&&t+j<=300;t++)
			dp[t+i][t+j][k]=1;
			for(int t=1;t+i<=300&&t+k<=300;t++)
			dp[t+i][j][t+k]=1;
			for(int t=1;t+j<=300&&t+k<=300;t++)
			dp[i][t+j][t+k]=1;
		}
	}
}
int main()
{
	init();
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c))//段错误,空间开的太大,开int是开Bool的4倍, 
	{
		printf("%d\n",dp[a][b][c]); 
	} 
	return 0; 
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值