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时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- HTML标签使用特写
页面定时刷新标签 //页面定时刷新 <meta http-equiv="> Input标记各种特殊用法 <%--禁止鼠标选择内容--%> <input id=& ...
- .NET常用方法收藏
1.过滤文本中的HTML标签 /// <summary> /// 清除文本中Html的标签 /// </summary> /// <param name="Co ...
- Linux下diff打补丁方法
tar zxvf php-5.2.14.tar.gz gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
- MVC controller and View
actionresult,jsonresult redirectresult partialview, viewdata, tempdata filter viewdata,只能在当前action中有 ...
- Java方法总结与源码解析(未完待续)
使用StringTokenizer去掉字符串中的空格 public class StringTo { public static void main(String[] args){ String te ...
- hdu 1361 Parencodings 简单模拟
Parencodings 题意: 由括号序列S可经P规则和W规则变形为P序列和W序列. p规则是:pi是第i个右括号左边的左括号的数: w规则是:wi是第i右括号与它匹配的左括号之间右括号的数(其中包 ...
- VI下删除所有内容
让光标在一个位置 , 如果全删就放在问价开始的位置 , 在非编辑的状态下输入dG(注意大小写) , 这样光标之后的所有行都会被删掉
- C++学习17派生类的构造函数
基类的构造函数不能被继承,在声明派生类时,对继承过来的成员变量的初始化工作也要由派生类的构造函数来完成.所以在设计派生类的构造函数时,不仅要考虑派生类新增的成员变量,还要考虑基类的成员变量,要让它们都 ...
- [ActionScript 3.0] AS3.0 获取像素点的灰度
/** * 获取像素点的灰度 * @color 像素点的颜色值 * @return uint */ function getGray(color:uint):uint { return getR(co ...
- [ActionScript 3.0] 通过三角形获得 3D 效果
Flash Player 10 和更高版本,Adobe AIR 1.5 和更高版本 在 ActionScript 中,使用Graphics.drawTriangles()方法执行位图转换,因为 3D ...