首页 技术 正文
技术 2022年11月9日
0 收藏 697 点赞 2,385 浏览 2137 个字

Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36986    Accepted Submission(s):
16885

Problem DescriptionNowadays, 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.

hdu 1087 Super Jumping! Jumping! Jumping!(最大上升子序列和)

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. InputInput contains multiple test cases. Each test case is
described in a line as follow:
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. OutputFor each case, print the maximum according to rules,
and one line one case. Sample Input3 1 3 24 1 2 3 44 3 3 2 10 Sample Output4 103 题目大意:用一句话总结就是 输入一个整数数列,输出该数列的最大上升子序列和。 解题思路:刚接触到这题的时候没什么思路 看了看网上的题解发现只是一个水DP(赶脚自己好菜啊~~)     只要把状态转移方程怼出来就可以了。对于这题来说可以定义一个dp数组     dp[i] 表示前i个整数组成的子串的最大上升子序列和     状态方程:dp[i]=max{dp[j]}+a[i]; 其中,0<=j<i,a[i]>a[j] ; 

 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n;
long long a[],dp[]; // dp[i] 储存从0到i的最大上升子序列的和
long long LIS() // 最大上升子序列和
{
int i,j;
long long sum = , maxx;
for (i = ; i < n; i ++)
{
dp[i] = a[i]; // dp[i]的初值为a[i]
maxx = ;
for (j = ; j < i; j ++) // 找出i之前的最大dp[i](并保证a[j] < a[i])
{
if (a[j] < a[i])
maxx = max(dp[j],maxx);
}
dp[i] += maxx;
sum = max(sum,dp[i]); // sum为最大上升子序列的和
}
return sum;
}
int main ()
{
while (scanf("%d",&n),n)
{
for (int i = ; i < n; i ++)
scanf("%lld",&a[i]);
printf("%lld\n",LIS());
}
return ;
}
下一篇: 19_ThreadLocal
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298