USACO Section 3.3 游戏 A Game
OJ:http://www.luogu.org/problem/show?pid=2734
#include<iostream>
#include<cstring>
using namespace std;
int n,sum,a[101],cal[101];
int mem[101][101];
int v[101][101];
int search(int s,int e){
if(v[s][e])
return mem[s][e];
v[s][e]=1;
if(s==e) return mem[s][e]=a[s];
return mem[s][e]=max(cal[e-1]-cal[s-1]-search(s,e-1)+a[e],
cal[e]-cal[s]-search(s+1,e)+a[s]);
}
void init()
{
memset(v,0,sizeof(v));
cal[0]=0;
sum=0;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
cal[i]=cal[i-1]+a[i];
sum+=a[i];
}
int x=search(1,n);
cout<<x<<" "<<sum-x;
return 0;
}
USACO Section 3.3 游戏 A Game的更多相关文章
- Cogs 763. [USACO Open09] 数字的游戏(博弈)
[USACO Open09] 数字的游戏 ★☆ 输入文件:cdgame.in 输出文件:cdgame.out 简单对比 时间限制:1 s 内存限制:128 MB Bessie正跟FJ玩一个数字游戏,她 ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- USACO Section 5.3 Big Barn(dp)
USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1 (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
- USACO Section 1.1-1 Your Ride Is Here
USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- iwpriv
AuthMode {OPEN,SHARED,WEPAUTO,WPAPSK,WPA2PSK,WPANONE} ::Set Authentication Mode EncrypTy ...
- [tty与uart]stty命令使用
中文解释链接:http://linux.51yip.com/search/stty 英文解释链接:http://pubs.opengroup.org/onlinepubs/9699919799/uti ...
- 216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- ZooKeeper典型应用场景(转)
ZooKeeper是一个高可用的分布式数据管理与系统协调框架.基于对Paxos算法的实现,使该框架保证了分布式环境中数据的强一致性,也正是基于这样的特性,使得ZooKeeper解决很多分布式问题.网上 ...
- Edmonds_Karp 算法入门详解(转)
转载自:http://blog.csdn.net/hsqlsd/article/details/7862903 有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点,通常规定为1号点.另一个点也 ...
- suibi 117
-Djava.net.preferIPv4Stack=true re.findall(r"^(\d+)" , content) content = content.replace( ...
- You need tcl 8.5 or newer in order to run the Redis test
安装Redis时候make test出现的 , 不用下什么tcl8.5再tar了 , 直接yum install tcl就好.
- Protobuf从安装到配置整理帖
新做的Mini项目计划使用Google的Protobuf来做,关于Protobuf是什么玩意能干什么请自己去看这里:http://code.google.com/p/protobuf/ 这里讲一下安装 ...
- netty入门实例
TimeServer.java package netty.timeserver.server; import io.netty.bootstrap.ServerBootstrap; import i ...
- DTD限制XML文件
需要通过使用Microsoft Visual Studio 2010.XMLSpy或者eclipse软件来检查校验 文件中有中文,需要存为utf-8编码 book.dtd <!ELEMENT 书 ...