HihoCoder1338 A Game(记忆化搜索)
描述
Little Hi and Little Ho are playing a game. There is an integer array in front of them. They take turns (Little Ho goes first) to select a number from either the beginning or the end of the array. The number will be added to the selecter's score and then be removed from the array.
Given the array what is the maximum score Little Ho can get? Note that Little Hi is smart and he always uses the optimal strategy.
输入
The first line contains an integer N denoting the length of the array. (1 ≤ N ≤ 1000)
The second line contains N integers A1, A2, ... AN, denoting the array. (-1000 ≤ Ai ≤ 1000)
输出
Output the maximum score Little Ho can get.
- 样例输入
-
- 4
- -1 0 100 2
- 4
- 样例输出
-
- 99
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- using namespace std;
- int a[],dp[][];
- int getdp(int L,int R)
- {
- if(dp[L][R]) return dp[L][R];
- if(L == R) return a[L];
- if(L==R-) dp[L][R]=max(a[L],a[R]);
- else dp[L][R]=max(a[L]+min(getdp(L+,R),getdp(L+,R-)),a[R]+min(getdp(L,R-),getdp(L+,R-)));
- return dp[L][R];
- }
- int main()
- {
- int n,i;
- scanf("%d",&n);
- for(i = ;i <= n;i ++) scanf("%d",&a[i]);
- printf("%d\n",getdp(,n));
- return ;
- }
HihoCoder1338 A Game(记忆化搜索)的更多相关文章
- [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...
- 【BZOJ-3895】取石子 记忆化搜索 + 博弈
3895: 取石子 Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 263 Solved: 127[Submit][Status][Discuss] D ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- zoj 3644(dp + 记忆化搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...
- loj 1044(dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...
- DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects
题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...
- HDU1978 记忆化搜索
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- bzoj4562: [Haoi2016]食物链--记忆化搜索
这道题其实比较水,半个小时AC= =对于我这样的渣渣来说真是极大的鼓舞 题目大意:给出一个有向图,求入度为0的点到出度为0的点一共有多少条路 从入读为零的点进行记忆化搜索,搜到出度为零的点返回1 所有 ...
- 数位dp/记忆化搜索
一.引例 #1033 : 交错和 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an ...
- poj3592 强连通+记忆化搜索
题意:有一片 n*m 的矿地,每一格有矿.或这传送门.或者挡路岩石.除了岩石不能走以外,其他的格子都能够向右或向下走,走到一个非岩石的格子.对于每一个矿点,经过它就能得到它的所有矿石,而对于每一个传送 ...
随机推荐
- [Java开发之路](8)输入流和输出流
1. Java流的分类 按流向分: 输入流: 能够从当中读入一个字节序列的对象称作输入流. 输出流: 能够向当中写入一个字节序列的对象称作输出流. 这些字节序列的来源地和目的地能够是文件,并且通常都是 ...
- pip源提示“not a trusted or secure host” 解决
问题:The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored ...
- hdu 2108 Shape of HDU【判断多边形是否是凸多边形模板】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2108 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- OC常用函数及变量
1.OC常用的的函数及变量 (1)算术函数 [算术函数] 函数名 说明 int rand() 随机数生成.(例)srand(time(nil)); //随机数初期化int val = rand()P; ...
- 如何将gedit变成c++编译器
本蒟蒻的第一篇文章,分享一下神佬教我的好东西 ——将Ubuntu 16.04上gedit变为编译器! 1° 新建文档.然后点击编辑,打开首选项. 2° 勾选外部工具,然后退出.打开工具,选择Manag ...
- proguard 不混淆第三方jar包的问题
导入lib文件,并且用-dontwarn 和 keep class结合试试,例如: -libraryjars libs/log4j.jar -dontwarn org.apache.log4j.*-k ...
- python3函数内全局变量使用global
def p_num(): global num num = 10 print (num) num = 5 p_num() print(num)
- Docker容器部署tomcat出现中文乱码
docker 容器部署tomcat后,日志文件中出现中文乱码,很多问号,中文的文件夹也是问好.先看看容器的locale: [root@docker1 ~]# docker exec -it 41de9 ...
- Gateway
网关在传输层上以实现网络互连,是最复杂的网络互连设备,仅用于两个高层协议不同的网络互连.网关的结构也和路由器类似,不同的是互连层.网关既可以用于广域网互连,也可以用于局域网互连. 网关是一种充当转换重 ...
- J2EE SSH框架整合教程
本文仅作为学习和研究的参考,与实际项目使用技术有所不同,由于作者水平有限,错误疏漏在所难免,请各位看官批评指教. 项目的源代码放在:https://github.com/Frank-Pei/SSHIn ...