A:Alice and Bob
2013-08-22 21:16
288 查看
Alice and Bob
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1395 Accepted Submission(s): 508
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!
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.
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
3 3 1 1 2 2 3 4 3 2 3 5
Sample Output
Case #1: Alice Case #2: Bob Case #3: Bob
Source
2011 Asia ChengDu Regional Contest
Recommend
Statistic | Submit | Discuss | Note
dp[i][j]表示有i个数是1,消去不为1的其他数字要j步(把数字减小和合并数字),为1表示先手赢,为0表示后手赢,为-1表示还没算出来
枚举找失败态.
dp数组一直保存下来记忆化;
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #define M 60 #define LL long long using namespace std; int a[55]; int dp[55][55*1000]; int cl(int i,int j){ if(dp[i][j]!=-1) return dp[i][j]; if(j==1) return dp[i][j]=cl(i+1,0); dp[i][j]=0; if(i>=1 && !cl(i-1,j)) dp[i][j]=1; else if(i>=1 && j>=1 && !cl(i-1,j+1)) dp[i][j]=1; else if(i>=2 && j>0 && !cl(i-2,j+3)) dp[i][j]=1; else if(i>=2 && j==0 && !cl(i-2,2)) dp[i][j]=1; else if(j>=2 && !cl(i,j-1)) dp[i][j]=1; return dp[i][j]; } int main(){ int T,cas=1; memset(dp,-1,sizeof(dp)); cin>>T; while(T--){ int n,i,sum=0,n1=0; cin>>n; for(i=0;i<n;i++){ cin>>a[i]; if(a[i]==1) n1++; sum+=a[i]; } int j=n1,k=sum-n1+n-n1-1; if(k<0) k++; cl(j,k); cout<<"Case #"<<cas++<<": "; if(dp[j][k]) puts("Alice"); else puts("Bob"); } return 0; }
相关文章推荐
- 2011 ACM-ICPC 成都赛区A题 Alice and Bob (博弈动规)
- hdu 4268 Alice and Bob(贪心)
- Sicily 1732 Alice and Bob (二进制最大公约数)
- 博弈——Alice and Bob
- Codeforces Round #325 (Div. 2) E. Alice, Bob, Oranges and Apples
- Codeforces Round #201 (Div. 2) - C. Alice and Bob
- HDU 4268 Alice and Bob(贪心)
- Codeforces 347C - Alice and Bob
- 长春赛区2012 Alice and Bob 1002题 (网络赛)
- Codeforces Round #201.C-Alice and Bob
- Alice and Bob (SG函数)
- Codeforces Round #201 (Div. 2) C. Alice and Bob ( 数学
- codeforces-346A-Alice and Bob【数论】
- Alice and Bob
- Sicily 1798. Alice and Bob
- HDU - 4268 Alice and Bob (set的应用)好题
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
- HDU 4111 Alice and Bob (博弈)
- Sicily 1798. Alice and Bob
- 山东省第四届ACM大学生程序设计竞赛 Alice and Bob