2018徐州網絡賽B題 BE, GE or NE (博弈記憶化搜索)

題目鏈接:https://nanti.jisuanke.com/t/31454

  •  262144K

In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly face the choice, each time you choose the game will provide 1-31−3 options, the player can only choose one of them. Each option has an effect on a "score" parameter in the game. Some options will increase the score, some options will reduce the score, and some options will change the score to a value multiplied by -1−1 .

That is, if there are three options in a selection, the score will be increased by 11, decreased by 11, or multiplied by -1−1. The score before the selection is 88. Then selecting option 11 will make the score become 99, and selecting option 22 will make the score 77 and select option 33 to make the score -8−8. Note that the score has an upper limit of 100100 and a lower limit of -100−100. If the score is 9999 at this time, an option that makes the score +2+2 is selected. After that, the score will change to 100100 and vice versa .

After all the choices have been made, the score will affect the ending of the game. If the score is greater than or equal to a certain value kk, it will enter a good ending; if it is less than or equal to a certain value ll, it will enter the bad ending; if both conditions are not satisfied, it will enter the normal ending. Now, Koutarou and Sena want to play the good endings and the bad endings respectively. They refused to give up each other and finally decided to use the "one person to make a choice" way to play the game, Koutarou first choose. Now assume that they all know the initial score, the impact of each option, and the kk, ll values, and decide to choose in the way that works best for them. (That is, they will try their best to play the ending they want. If it's impossible, they would rather normal ending than the ending their rival wants.)

Koutarou and Sena are playing very happy, but I believe you have seen through the final ending. Now give you the initial score, the kk value, the ll value, and the effect of each option on the score. Can you answer the final ending of the game?

Input

The first line contains four integers n,m,k,ln,m,k,l(1\le n \le 10001≤n≤1000, -100 \le m \le 100−100≤m≤100 , -100 \le l < k \le 100−100≤l<k≤100), represents the number of choices, the initial score, the minimum score required to enter a good ending, and the highest score required to enter a bad ending, respectively.

Each of the next nn lines contains three integers a,b,ca,b,c(a\ge 0a≥0 , b\ge0b≥0 ,c=0c=0 or c=1c=1),indicates the options that appear in this selection,in which a=0a=0 means there is no option to increase the score in this selection, a>0a>0 means there is an option in this selection to increase the score by aa ; b=0b=0 means there is no option to decrease the score in this selection, b>0b>0 means there is an option in this selection to decrease the score by bb; c=0c=0 means there is no option to multiply the score by -1−1 in this selection , c=1c=1 means there is exactly an option in this selection to multiply the score by -1−1. It is guaranteed that a,b,ca,b,c are not equal to 00 at the same time.

Output

One line contains the final ending of the game. If it will enter a good ending,print "Good Ending"(without quotes); if it will enter a bad ending,print "Bad Ending"(without quotes);otherwise print "Normal Ending"(without quotes).

樣例輸入1複製

3 -8 5 -5
3 1 1
2 0 1
0 2 1

樣例輸出1複製

Good Ending

樣例輸入2複製

3 0 10 3
0 0 1
0 10 1
0 2 1

樣例輸出2複製

Bad Ending

 

題意就是兩個人輪流進行n輪操作 每輪選三種操作中的一個 增加 減少 取反  一個儘可能讓分數高 另一個儘可能讓分數低

給你l,r判斷最後分數的好壞 

拿到這道題一看是個博弈 我們隊博弈沒人搞 自己又yy覺得跟博弈dp很像 就被自己帶偏了 因爲數據量小能夠暴力也想到了記憶化搜索 偏偏dp記錄的值不簡單記錄最後的結果 死磕狀態的期望值 結果死到了比賽結束

這類還是跟博弈dp有點差別的 博弈dp兩個人的操作是相同的 目的也相同 而這道題並不是這樣 只能記憶化搜索

如果當前好人面對的全是最終分數是壞的選擇 那他面臨的狀態必然是壞的 反之亦然

如果當前好人面臨不全是壞的 一旦有一個是好局面 那他一定選好的 如果沒有好局面 存在一箇中等局面 那他一定選中等的 

如此一來分類討論一下就出來了 反之亦然

#include <bits/stdc++.h>
using namespace std;
#define py 150
struct xjy
{
    int a,b,c;
}s[1111];
int dp[1111][333];
int n,m,l,r;
int dfs(int now,int sco)
{
    if(now>n)
    {
        if(sco<=l)
            return -1;
        else if(sco>=r)
            return 1;
        else
            return 0;
    }
    if(dp[now][sco+py]!=3)
        return dp[now][sco+py];
    int a=2,b=2,c=2;
    if(s[now].a)
        a=dfs(now+1,min(100,sco+s[now].a));
    if(s[now].b)
        b=dfs(now+1,max(-100,sco-s[now].b));
    if(s[now].c)
        c=dfs(now+1,-sco);
    if((a==1||b==1||c==1)&&(now&1))
    {
        dp[now][sco+py]=1;
        return 1;
    }
    else if((a==-1||b==-1||c==-1)&&((now&1)==0))
    {
        dp[now][sco+py]=-1;
        return -1;
    }
    else if(((a==-1||a==2)&&(b==-1||b==2)&&(c==-1||c==2))&&(now&1))
    {
        dp[now][sco+py]=-1;
        return -1;
    }
    else if((a==1||a==2)&&(b==1||b==2)&&(c==1||c==2)&&((now&1)==0))
    {
        dp[now][sco+py]=1;
        return 1;
    }
    else
    {
        dp[now][sco+py]=0;
        return 0;
    }

}
int main()
{
    while(~scanf("%d%d%d%d",&n,&m,&r,&l))
    {
        for(int i=0;i<1111;i++)
        {
            for(int j=0;j<333;j++)
                dp[i][j]=3;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&s[i].a,&s[i].b,&s[i].c);
        }
        int ans=dfs(1,m);
        if(ans==1)
            printf("Good Ending\n");
        else if(ans==0)
            printf("Normal Ending\n");
        else
            printf("Bad Ending\n");
    }
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章