hdu 1087 最长上升序列和 dp
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56910 Accepted Submission(s): 26385
a kind of chess game called “Super Jumping! Jumping! Jumping!” is very
popular in HDU. Maybe you are a good boy, and know little about this
game, so I introduce it to you now.
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.
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.
#include<iostream>
#include<string.h>
using namespace std;
int a[],dp[];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n;
while(cin>>n&&n!=)
{
for(int i=;i<n;i++)
cin>>a[i];
memset(dp,,sizeof(dp));
dp[]=a[];
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
{
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+a[i]);
}
dp[i]=max(dp[i],a[i]); }
int ans=dp[];
for(int i=;i<n;i++)
ans=max(ans,dp[i]);
cout<<ans<<endl;
}
return ;
}
最新文章
- jQuery系列:Ajax
- Linux从零单排(一):Google Chrome的安装
- (转)TortoiseSVN客户端重新设置用户名和密码
- spring boot单元测试(转)
- iOS开发——OC篇&;协议篇/NSCoder/NSCoding/NSCoping
- yii项目开发项目常用技巧和方法汇总
- labview 移位寄存器、隧道、索引隧道的区别
- POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)
- remastersys
- Quiz 6a Question 7————An Introduction to Interactive Programming in Python
- NOIP 2017 Day 0. 游记
- Java开发知识之Java面相对象
- (办公)SpringBoot和swagger2的整合.
- PHP博大精深,入门容易,精通难,怎么才能真正学好PHP
- 提高CPU使用率100%
- 你真的了解String的常见API吗?
- mysql 5.5 数据库 utf8改utf8mb4
- 第5月第10天 node.js的request模块
- McAfee 与 360使用感受
- Windows下Sqlplus中显示乱码