CodeForces 731E Funny Game
博弈,$dp$。
设$f[i]$表示 如果先手第一次出手取到位置$i$,直到游戏结束,双方均采取最优策略,先手-后手得分的差值。
那么$f[i]=min(sum[i]-sum[j]+maxf[j+1])$,取$min$是因为后手采取最优策略,取$maxf$是因为先手采取最优策略。最终答案就是$max(f[i])$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} long long sum[],a[];
long long maxf[],f[],ans,x;
int n; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++) sum[i]=sum[i-]+a[i]; maxf[n]=f[n]=sum[n];
f[n-]=sum[n-]-sum[n];
maxf[n-]=max(maxf[n],f[n-]);
x=-sum[n-]+f[n]; for(int i=n-;i>=;i--)
{
f[i]=min(sum[i]+x,sum[i]-sum[n]);
maxf[i]=max(maxf[i+],f[i]);
x=min(x,-sum[i]+maxf[i+]);
} ans=f[n];
for(int i=;i<=n;i++) ans=max(ans,f[i]);
cout<<ans<<endl; return ;
}
CodeForces 731E Funny Game的更多相关文章
- 【codeforces 731E】Funny Game
[题目链接]:http://codeforces.com/contest/731/problem/E [题意] 两个人轮流玩游戏; 取序列中的前k(k>1)个数字,拿出来; 把这k个数字全部加起 ...
- ACM 博弈(难)题练习 (第一弹)
第二弹: 套路&&经验总结: 1. N堆***的游戏,一般可以打表找SG函数的规律.比如CodeForces 603C 2.看起来是单轮的游戏,实际上可能拆分成一些独立的子游戏.比如C ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- [LeetCode] 2. Add Two Numbers ☆☆
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
- 51Nod 1007 正整数分组 | DP (01背包)
Input示例 5 1 2 3 4 5 Output示例 1 分析:2组的差最小,那么每一组都要接近sum/2,这样就转化成了普通的0 - 1背包了 #include <bits/stdc++. ...
- Robot Framework Chrome
1. 下载对应版本的chromedriver, 好像都是windows32位的,不过没关系,可以用即可. 2. 将chromedriver放入到chrome的安装路径下,然后将chromrdriver ...
- for in、each; for 、forEach、map
1.jQuery.each(object, [callback]) 用于例遍任何对象.回调函数拥有两个参数:第一个为对象的成员或数组的索引,第二个为对应变量或内容.如果需要退出 each 循环可使回调 ...
- 6.0docker Dockerfile文件
指令格式 #注释 FROM :基础镜像 MAINTAINER:镜像的作者信息 RUN :指定(构建过程中)当前镜像中运行的命令 EXPOSE :指定运行镜像的容器应用程序所使用的端口 容器但不会打开, ...
- TensorFlow中get_variable共享变量调用
import tensorflow as tf with tf.variable_scope('v_scope',reuse=True) as scope1: Weights1 = tf.get_va ...
- st2-045漏洞利用poc
use LWP::UserAgent; undef $/; ){print "Use:poc.pl http://target/index.action\n";exit;} my ...
- ubuntu安装wifi
因为需要测试app,但是自己本地是deepin.如果win下的话直接安装一个wifi万能管家啥的就完事儿了.可是这个是linux 有点不同.所以就进行百度学习了一波.特此分享. 需要用到的工具 hos ...
- 不要用Serverzoo 提供的CloudLinux 的五大原因 Linode 強大VPS 資源為你解密
不要用Serverzoo 提供的CloudLinux 的五大原因 Linode 強大VPS 資源為你解密 https://www.williamformosa.com/cloud-linux/
- XMLDocument 方法中实现post发送消息
XMLDocument 方法中实现post发送消息