Hdu4111Alice and Bob(dp+博弈论)
来源:互联网 发布:vr需要学什么编程语言 编辑:程序博客网 时间:2024/06/16 08:44
Alice and Bob
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1540 Accepted Submission(s): 563
Problem Description
Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that's why they feel bored again and again. They just invented a new game, as they usually did.
The rule of the new game is quite simple. At the beginning of the game, they write down N random positive integers, then they take turns (Alice first) to either:
1. Decrease a number by one.
2. Erase any two numbers and write down their sum.
Whenever a number is decreased to 0, it will be erased automatically. The game ends when all numbers are finally erased, and the one who cannot play in his(her) turn loses the game.
Here's the problem: Who will win the game if both use the best strategy? Find it out quickly, before they get bored of the game again!
The rule of the new game is quite simple. At the beginning of the game, they write down N random positive integers, then they take turns (Alice first) to either:
1. Decrease a number by one.
2. Erase any two numbers and write down their sum.
Whenever a number is decreased to 0, it will be erased automatically. The game ends when all numbers are finally erased, and the one who cannot play in his(her) turn loses the game.
Here's the problem: Who will win the game if both use the best strategy? Find it out quickly, before they get bored of the game again!
Input
The first line contains an integer T(1 <= T <= 4000), indicating the number of test cases.
Each test case contains several lines.
The first line contains an integer N(1 <= N <= 50).
The next line contains N positive integers A1 ....AN(1 <= Ai <= 1000), represents the numbers they write down at the beginning of the game.
Each test case contains several lines.
The first line contains an integer N(1 <= N <= 50).
The next line contains N positive integers A1 ....AN(1 <= Ai <= 1000), represents the numbers they write down at the beginning of the game.
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is either "Alice" or "Bob".
Sample Input
331 1 223 432 3 5
Sample Output
Case #1: AliceCase #2: BobCase #3: Bob
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>using namespace std;#define LL __int64int sg[60][60000];int dp(int a,int b){if (sg[a][b]!=-1) return sg[a][b];if (b==1) return sg[a][b]=dp(a+1,0);sg[a][b]=0;if (a>0&&!dp(a-1,b))sg[a][b]=1;if (b>0&&!dp(a,b-1))sg[a][b]=1;if (a>0&&b&&!dp(a-1,b+1))sg[a][b]=1;if (a>1&&((b==0&&!dp(a-2,b+2))||(b&&!dp(a-2,b+3))))sg[a][b]=1;return sg[a][b];}int main(){int T,n,i,x,y,z;memset(sg,-1,sizeof(sg));scanf("%d",&T);for (int c=1;c<=T;c++){y=0;z=0;scanf("%d",&n);for (i=1;i<=n;i++){scanf("%d",&x);if (x==1)y++;else z+=x+1;}if (z) z--;dp(y,z);printf("Case #%d: ",c);if (sg[y][z]) puts("Alice");else puts("Bob");}return 0;}
0 0
- Hdu4111Alice and Bob(dp+博弈论)
- hdu4111Alice and Bob+SG博弈
- hdu4111 Alice and Bob 博弈论
- poj1704 Georgia and Bob博弈论
- [博弈论]A Game Between Alice and Bob
- POJ 1704 Georgia and Bob(nim博弈论)
- HDU 4111 Alice and Bob 博弈论
- hdu 4111 Alice and Bob 博弈论 sg函数
- XinanTanOJ 1168 Alice and Bob 二维DP
- XTU1168:Alice and Bob(二维DP)
- UVA - 1500 Alice and Bob (dp+博弈)
- ZOJ 3529 A Game Between Alice and Bob(博弈论-sg函数)
- POJ-1704(Georgia and Bob)——博弈论、SG函数
- [HDU] 3660 Alice and Bob's Trip -- 树形DP?
- hdoj 3660 Alice and Bob's Trip(树dp)
- hdu4111 Alice and Bob---sg dp记忆化求sg
- uva 1484 Alice and Bob's Trip (树形dp)
- hdu - 3660 - Alice and Bob's Trip(树形dp)
- 大数相除
- LeetCode Swap Nodes in Pairs
- python list列表操作
- open ps failed. errno: Permission denied
- 深度探索C++对象模型----Data语义学
- Hdu4111Alice and Bob(dp+博弈论)
- 类、抽象类、接口
- &--引用声明符
- Java类加载机制
- 不要62 hdoj 2089
- 博弈
- MetaQ (RocketMQ) 小包消息优化项目中期总结
- 同步,异步,并发的区别
- Agri-Net