ACM-ICPC 2018 徐州赛区网络预赛(重现)

题目:B - BE, GE or NE 计蒜客 - A2001

分析:

记忆化搜索,dp[pos][val]表示进行第pos轮的时候,分数为val的结果(2表示good ending,1表示normal,0表示bad,先手希望值越大越好,后手相反)。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;//三年竞赛一场空,不开long long见祖宗 
//typedef __int128 lll;
#define print(i) cout << "debug: " << i << endsl
#define close() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define x first
#define y second
typedef pair<int, int> pii;
const ll mod = 1e9 + 7;
const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
int n, m, high, low;
int a[maxn], b[maxn], c[maxn];
map<int, map<int, int>> dp;

int dfs(int pos, int val)
{
    if(pos == n + 1)
        return val >= high ? 2 : val > low ? 1 : 0;
    if(~dp[pos][val]) return dp[pos][val];
    int res = pos % 2 ? 0 : 2;
    if(pos & 1)
    {
        if(a[pos]) res = max(res, dfs(pos + 1, min(100, val + a[pos])));
        if(b[pos]) res = max(res, dfs(pos + 1, max(-100, val - b[pos])));
        if(c[pos]) res = max(res, dfs(pos + 1, -val));
    }
    else
    {
        if(a[pos]) res = min(res, dfs(pos + 1, min(100, val + a[pos])));
        if(b[pos]) res = min(res, dfs(pos + 1, max(-100, val - b[pos])));
        if(c[pos]) res = min(res, dfs(pos + 1, -val));
    }
    return dp[pos][val] = res;
}

int main()
{
    cin >> n >> m >> high >> low;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
    for(int i = 1; i <= n; i++)
        for(int j = -100; j <= 100; j++)
            dp[i][j] = -1;
    int res = dfs(1, m);
    if(res == 2) cout << "Good Ending" << endl;
    else if(res == 1) cout << "Normal Ending" << endl;
    else cout << "Bad Ending" << endl;
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值