Atc dp_l
题意 给你一个序列
一个人先拿 另一个人后拿 只能从序列的开头或者结尾拿一个元素
先拿的分数是 X 后拿的人分数是 Y
他们都想要自己的分数差最大 也就是第一个人是 X - Y最大
第二个人是 Y - X最多
我们发现对这类dp 只有dp[l][r] 代表区间 l 到 区间 r 的最大 X - Y
只有当L = R的时候 才能确定取的是arr[l],arr[R]
如果不等于 就从上个状态 arr[L] - dp[L+1][R] , arr[R] - dp[L][R-1]
推过来 为什么要减 因为上个人的值正好是下个人的负值
因为是L + 1 所以我们 L 从n 到 1
因为是R - 1 所以我们R 从 L 到 n
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" =

这篇博客介绍了Atcoder中一个关于动态规划(DP)的问题,涉及两人轮流从序列两端取元素的游戏。目标是最大化各自的得分差。作者解释了如何利用deque来处理该DP问题,讨论了当区间长度为1时确定取哪个元素的情况,以及在L不等于R时如何根据上一状态推导当前状态的策略。
最低0.47元/天 解锁文章
522

被折叠的 条评论
为什么被折叠?



