ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE(记忆化搜索)

题目链接

题目大意:现在有两个人在做游戏,这个游戏是这样的,它分为n轮,然后是一人一轮,每一轮次都有着三个操作,分别是给当前的分数加上a,给当前的分数减去b,使得当前的分数乘上-1,然后一个人想着能不能把最后的分数>=k,一个人想着能不能把分数变成<=l,如果第一个人赢了输出good ending,如果第二个人赢了,则输出bad ending ,否则输出 normal ending

思路:今天打的重现赛,一开始没什么思路,后来下来搜索题解的时候,发现我们的题意读错了,他应该是一个人一轮,而不是一轮取两个操作,后来得知了正确的题意也就比较好想了,因为我们可以暴力搜索他可能有的而且是一定会有的得分,因为我们的爆搜包含了所有的情况,后来发现好像会有很多的重复的状态,那么我们就用dp【pos】【score】给标记一下就好了,其中那个score是用的map映射了一下,因为score可能是负值的,

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
const int maxn=1000+10;
int dp[maxn][200+10];
int a[maxn],b[maxn],c[maxn];
int n,m,k,l;
map<int ,int >id;
int DFS(int pos,int sco)
{
    if(pos==n+1)
    {
        if(sco>=k)return 2;
        else if(sco<=l)return 0;
        else return 1;
    }
    if(dp[pos][id[sco]]!=-1)
        return dp[pos][id[sco]];
    if(pos&1)
    {
        int ret=0,temp=sco;
        temp=min(100,sco+a[pos]);
        if(a[pos])
        {
            ret=max(ret,DFS(pos+1,temp));
        }
        temp=max(-100,sco+b[pos]);
        if(b[pos])
        {
            ret=max(ret,DFS(pos+1,temp));
        }
        if(c[pos])
        {
            ret=max(ret,DFS(pos+1,-sco));
        }
        return dp[pos][id[sco]]=ret;
    }
    else
    {
        int ret=2,temp=sco;
        temp=min(100,sco+a[pos]);
        if(a[pos])
        {
            ret=min(ret,DFS(pos+1,temp));
        }
        temp=max(-100,sco+b[pos]);
        if(b[pos])
        {
            ret=min(ret,DFS(pos+1,temp));
        }
        if(c[pos])
        {
            ret=min(ret,DFS(pos+1,-sco));
        }
        return dp[pos][id[sco]]=ret;
    }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    for(int i=-100,cnt=1;i<=100;i++)
        id[i]=cnt++;
    scanf("%d%d%d%d",&n,&m,&k,&l);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&a[i],&b[i],&c[i]),b[i]=-b[i];
    int ans=DFS(1,m);
    if(ans==0)
        printf("Bad Ending\n");
    else if(ans==1)
        printf("Normal Ending\n");
    else
        printf("Good Ending\n");
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值