当前位置:网站首页>Super Jumping! Jumping! Jumping!
Super Jumping! Jumping! Jumping!
2022-06-28 08:31:00 【Angeliaaa】
Nowadays, 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( The board )and some chessmen( pieces ), 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
Input 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.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
Sample Output
4 10 3
The question : Give me a number n, Represents the total number of pieces , After that n The number of pieces is the value of each piece , The latter is always bigger than the former , Find the maximum sum of pieces to walk .
Ideas : The question is dp thought , Use two layers for loop , find i The previous value is higher than i Small and num【j】 maximal , And then to num【i】=num【j】+a【i】, Then output the largest one . The code is as follows :
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long int a[1010],num[1010];
int main()
{
int n,i,j;
long long maxx,t;
while(~scanf("%d",&n)&&n)
{
maxx=-1;
memset(num,0,sizeof(num));
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
for(i=0;i<n;i++)
{
t=0;
for(j=i-1;j>=0;j--)
{
if(a[j]<a[i]&&t<num[j])
t=num[j];
}
num[i]=t+a[i];
maxx=max(maxx,num[i]);
}
printf("%lld\n",maxx);
}
return 0;
}
边栏推荐
猜你喜欢
Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
【学习笔记】拟阵
B_QuRT_User_Guide(28)
Kubernetes notes and the latest k3s installation introduction
Kali Notes(1)
Build an integrated kubernetes in Fedora
Installing mysql5.7 under Windows
利尔达低代码数据大屏,铲平数据应用开发门槛
After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
Introduction, compilation, installation and deployment of Doris learning notes
随机推荐
js取整的小技巧
Build an integrated kubernetes in Fedora
【Go ~ 0到1 】 第三天 6月27 slice,map 与 函数
PLSQL installation under Windows
11grac turn off archive log
App automated testing appium Tutorial Part 1 - advanced supplementary content
[introduction to SQL in 10 days] day5+6 consolidated table
Chenglian premium products donated love materials for flood fighting and disaster relief to Yingde
[learning notes] simulation
Introduction, compilation, installation and deployment of Doris learning notes
Login common test case
redis02——一篇终结redis的五种数据类型操作命令(可学习、复习、面试、收藏备用)
Devops foundation chapter Jenkins deployment (II)
The RAC cannot connect to the database normally after modifying the scan IP. The ora-12514 problem is handled
TCP
Unity - use of API related to Pico development input system ---c
抗洪救灾,共克时艰,城联优品捐赠10万元爱心物资驰援英德
Installing MySQL under Linux
nuxt3入门
ROS notes (09) - query and setting of parameters