hdu 2147 kiki's game(DP(SG)打表找规律)

题意:

n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边。

无法移动硬币的人负。

给出n和m,问,先手胜还是后手胜。

数据范围:

n, m (0<n,m<=2000)

思路:

dp[i][j]=0,说明从(i,j)这个点到时左下角先手败。dp[i][j]=1则先手胜。

然后记忆搜。但是记忆搜会超时。

搜完把整张表打出来,发现规律了,,,,然后,,,代码剩几行了。

代码:

///打表观察

/*
int f[2005][2005];

int go(int n,int m){ //0:必败 1:必胜
    if(f[n][m]!=-1) return f[n][m];
    int a1 = n-1, b1 = m;
    int a2 = n, b2 = m-1;
    int a3 = n-1,b3 = m-1;

    if(a1>=1 && b1>=1 && go(a1,b1)==1) return f[n][m] = 0;
    if(a2>=1 && b2>=1 && go(a2,b2)==1) return f[n][m] = 0;
    if(a3>=1 && b3>=1 && go(a3,b3)==1) return f[n][m] = 0;
    return f[n][m] = 1;
}
*/

int main(){
    int n,m;

    while(scanf("%d%d",&n,&m),n||m){
        /*
        rep(i,1,n)
            rep(j,1,m) f[i][j] = -1;

        f[1][1] = 0;

        go(n,m);

        rep(i,1,n){
            rep(j,1,m) printf("%d",f[i][j]); cout<<endl;
        }
        */
        if(n%2 && m%2)
            puts("What a pity!");
        else
            puts("Wonderful!");
    }
}

hdu 2147 kiki's game(DP(SG)打表找规律)

时间: 2024-10-10 13:20:51

hdu 2147 kiki's game(DP(SG)打表找规律)的相关文章

HDU 3032 (SG打表找规律)

题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围比较大,所以最好通过SG打表的结果找出规律在解. sg(4k+1)=4k+1;sg(4k+2)=4k+2;sg(4k+3)=4k+4; sg(4k)=4k-1; 1 2 4 3 5 6 8 7 Sample Input232 2 323 3 Sample OutputAliceBob SG打表找规律

石油大训练 Little Sub and Johann (博弈SG打表找规律)

Little Sub and Johann 题目描述 Little Sub and Johann are good friends and they often play games together. Recently, they like playing with stones.They have n piles of stones initially and they should make one of following movements by turns:1.Erase a pil

hdu 3032 sg打表找规律 *

有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 using namespace std; 6 const int N=1000010; 7 int sg[N];

HDU 3032 Nim or not Nim?(博弈 SG打表找规律)

传送门 Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1457    Accepted Submission(s): 720 Problem Description Nim is a two-player mathematic game of strategy in which players take

HDU 2147 —— kiki&#39;s game

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others) Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of th

HDU 2147 kiki&#39;s game(博弈图上找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题目大意:给你一个n*m的棋盘,初始位置为(1,m),两人轮流操作,每次只能向下,左,左下这三个方向移动,谁最后无法移动棋子就输掉比赛,问先手是否会获胜. 解题思路:简单题,P/N分析找规律,以(n,m)点为结束点推到起始点,如图: 发现每个田字格的状态都是一样的,因为(n,m)点一定时P态,所以可以得出规律:只有当(m%2==1&&n%2==1)时,先手才会输. 代码: 1 #incl

HDU 2147 kiki&#39;s game(规律,博弈)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 10763    Accepted Submission(s): 6526 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his

hdu 2147 kiki&#39;s game 博弈

点击打开链接链接 kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total Submission(s): 6933    Accepted Submission(s): 4141 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears

HDU 2147 kiki&#39;s game(巴什博弈论)

题目地址:HDU 2147 又是一道NP状态转换的巴什博弈.这题根据NP状态转移最好画个表格,规律就很直观了. 博弈么,从左下角往前推: P→到达该点后,下一个人必败. N→到达该点后,下一个人必胜. 显然,最左下角的点是P. 然后根据经过一步操作可到达必败状态的都是必胜状态,下一步操作都是必胜状态,那么这步操作时必败状态的原则一步步的去画表格就可以了.