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时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- TMS320C54x系列DSP的CPU与外设——第5章 数据寻址
第5章 数据寻址 C54x DSP提供7种基本寻址方式. ■ Immediate addressing uses the instruction to encode a fixed value. ...
- shell脚本摘要
开启监听端口的程序时,查看是否开启成功(该例子监听8983端口) #动态显示[|][/][-][\] function spinner() { local pid=$1 local delay=0.5 ...
- Codeforces Round #364 (Div. 2) Cards
Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...
- [实变函数]2.1 度量空间 (metric space), $n$ 维 Euclidean 空间
1 回忆: $$\bex \lim_{n\to\infty}a_n=a\lra \forall\ \ve>0,\ \exists\ N,\ \forall\ n\geq N,\mbo ...
- uboot 的内存命令使用 mw (修改) md (显示)
修改:mw [内存地址] [值] [长度] 例如:mw 0x02000000 0 128 表示修改地址为0x02000000~0x02000000+128的内存值为0. 显示:md [内存地址] [长 ...
- firebug下载时出现there was an error loading firebug
打开Firefox -> Preferences -> Advance ->Certificates 将Query OSCP....前面的checkbox取消
- Web Service 性能测试工具比较
背景 希望选择一款Web Service性能测试工具,能真实模拟大量用户访问网站时的请求,从而获取服务器当前的请求处理能力(请求数/秒).以微信服务器为例,每个用户用独立的登录token,做各种操作, ...
- shell test -n -z
z --- zero 字符串长度为零 2)判断字符串 test –n 字符串 字符串的长度非零 test –z 字符串 ...
- DataTable.select() 返回 DataTable
DataTable.select() 默认返回值为 DataRow[]数组 代码来自网络: /**/ /// <summary> /// 执行DataTable中的查询返回新的DataTa ...
- java学习___File类的创建
一.使用File创建文件 File file = new File("."+File.separator+"data.dat"); //如果不存在则创建 fil ...