当前位置:网站首页>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;
}
边栏推荐
- Devops Basics: Jenkins deployment and use (I)
- VMware Workstation related issues
- 小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站
- [learning notes] differential constraint
- [go ~ 0 to 1] the next day, June 25, switch statement, array declaration and traversal
- Redis02 -- an operation command of five data types for ending redis (it can be learned, reviewed, interviewed and collected for backup)
- Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
- Selenium reptile
- JS rounding tips
- 2022巴黎时装周儿童单元6.19武汉站圆满落幕
猜你喜欢

DB

Why MySQL cannot insert Chinese data in CMD

关于如何在placeholder中使用字体图标

新唐NUC980使用记录:自制开发板(基于NUC980DK61YC)

小艺人黄鑫洋受邀参加巴黎时装周儿童单元武汉站

VMware Workstation related issues

What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?

2022第六季完美童模 佛山赛区 初赛圆满落幕

The 6th smart home Asia 2022 will be held in Shanghai in October

PLSQL installation under Windows
随机推荐
探讨gis三维系统在矿山行业中的应用
AWS builds a virtual infrastructure including servers and networks (2)
[learning notes] search
Almost Union-Find(带权并查集)
DB
In flood fighting and disaster relief, the city donated 100000 yuan of love materials to help Yingde
[learning notes] shortest path + spanning tree
Priority of JS operator
2022第六季完美童模 佛山赛区 初赛圆满落幕
【学习笔记】线性基
VMware Workstation related issues
The micro kernel zephyr is supported by many manufacturers!
B_QuRT_User_Guide(26)
PLSQL installation under Windows
Tree
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
【力扣10天SQL入门】Day4 组合查询 & 指定选取
Installing mysql5.7 under Windows
B_QuRT_User_Guide(28)
Sword finger offer 03 Duplicate number in array