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时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- (微信API接口开发) 使用HttpWebRequest进行请求时发生错误:基础连接已关闭,发送时发生错误处理
最近调试原来的微信模拟登陆时发生了“基础连接已关闭,发送时发生错误”的错误提示,原来都是好好的,只是很久没用了. 出错代码如下: HttpWebRequest req = (HttpWebReques ...
- 黄聪:使用$.getJSON解决ajax跨域访问 JQuery 的跨域方法(服务器端为wordpress程序)
客户端: <input id="cat" name="cat" type="hidden" value="<? ech ...
- 深入分析Volatile的实现原理(转)
引言 在多线程并发编程中synchronized和Volatile都扮演着重要的角色,Volatile是轻量级的synchronized,它在多处理器开发中保证了共享变量的“可见性”.可见性的意思是当 ...
- could not open extension control file "/usr/share/postgresql/9.1/extension/plpythonu.control": No such file or directory
在使用createlang 安装plpythonu的时候出现如下错误:could not open extension control file "/usr/share/postgresql ...
- CF109 C. Lucky Tree 并查集
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal re ...
- eclipse升级,导入旧版eclipse的插件[转]
启动 eclipse.菜单 File => import … => Install => From existing Installation, 点确定, 就会弹出对话框, 浏览选择 ...
- linux命令行下导出导入.sql文件
一.导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径):1.导出数据和表结构(以管理员身份运行): ------------------------------------ ...
- android之SeekBar控件用法
MainActivity.java package com.example.mars_2400_seekbar; import android.support.v7.app.ActionBarActi ...
- Xcode7--坑无法运行iOS9以下的模拟器
Unable to open liblaunch_sim.dylib. Try reinstalling Xcode or the simulator 解决办法 一.找到目标文件 /Applicati ...
- linux内核神级list
源码: #ifndef _LINUX_LIST_H #define _LINUX_LIST_H /* * Simple doubly linked list implementation. * * S ...