hdu1087 简单DP
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
Sample Input
4 1 2 3 4
4 3 3 2 1
0
Sample Output
10
3
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;
const int maxn=1000+100;
int dp[maxn],a[maxn];
const int inf=0xfffffff;
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
dp[1]=a[1];
int ma=-inf;
for(int i=2;i<=n;i++)
{
dp[i]=a[i];
for(int j=i-1;j>=1;j--)
{
if(a[i]>a[j])
dp[i]=max(dp[i],a[i]+dp[j]);
}
if(dp[i]>ma)
ma=dp[i];
}
cout<<ma<<endl;
}
return 0;
}
hdu1087 简单DP的更多相关文章
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- Codeforces 41D Pawn 简单dp
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...
- poj1189 简单dp
http://poj.org/problem?id=1189 Description 有一个三角形木板,竖直立放.上面钉着n(n+1)/2颗钉子,还有(n+1)个格子(当n=5时如图1).每颗钉子和周 ...
随机推荐
- 带你深入了解Web站点数据库的分布存储
作者:finalbsd原载: http://www.sanotes.net/html/y2009/358.html 在Web 2.0时代,网站将会经常面临着快速增加的访问量,但是我们的应用如何满足用户 ...
- 40条优化php代码的小实例
1.如果一个方法能被静态,那就声明他为静态的,速度可提高1/4; 2.echo的效率高于print,因为echo没有返回值,print返回一个整型; 3.在循环之前设置循环的最大次数,而非在在循环中; ...
- z-index 所遇问题
document.getElementById('wx_share_img').style.cssText = "width:100%;height:100%;position:fixed; ...
- bzero()等的区别
bzero 原型: extern void bzero(void *s, int n); 用法: #include <string.h> 功能:置字节字符串s的前n个字节为零. 说 ...
- 64位调试器花费的时间比预期的要长(A 64-bit debugging operation is taking longer than expected)
在stackoverflow上找到解决方案的: http://stackoverflow.com/questions/21329899/vs2013-professional-local-64-bit ...
- Maven, IntellJ Idea 配置注意点
1. Maven要自己安装一个: 2. Maven设置中,settings.xml和repository地址都配置成自己: 3. Enable Auto import 4. 找不到jar文件时,自己的 ...
- libeXosip2(3-1) -- eXosip2 INVITE and Call Management
eXosip2 INVITE and Call Management SIP messages and call control API Functions int eXosip_call_set_ ...
- C++ double类型转string类型后,怎么实现小数点后只显示一个数字
C++ double类型转string类型后,怎么实现小数点后只显示一个数字 #include <iostream> #include <sstream> #include & ...
- 【转】修改Android工程的名称、安装路径
申明:转载自:http://blog.csdn.net/hcj116/article/details/21712353 在Google提供的Eclipse集成开发环境adt-bundle下修改名称的总 ...
- pyqt记录内容(音乐播放器)
#这是UI文件 # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'AudioPlayerDia ...