当前位置:网站首页>Super Jumping! Jumping! Jumping!
Super Jumping! Jumping! Jumping!
2022-06-28 08:10: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(棋盘)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
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
题意:给出一个数字n,代表总棋子数,之后的n个数是每个棋子的数值,走的时候后者总要比前者大,求走的最大棋子总和。
思路:这个题是dp思想,用两层for循环,找到 i 之前数值比 i 小并且num【j】最大的,然后给num【i】=num【j】+a【i】,然后输出最大的那个即可。代码如下:
#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;
}
边栏推荐
- 安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
- Is it reliable for flush to register and open an account? Is it safe?
- 关于在cmd中MySQL不能插中文数据的原因
- Selenium+chromedriver cannot open Google browser page
- Leetcode swing series
- 【学习笔记】模拟
- MySQL tablespace parsing
- 新唐NUC980使用记录:自制开发板(基于NUC980DK61YC)
- Trigonometric transformation formula
- Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
猜你喜欢

你了解TCP协议吗(二)?
![[learning notes] matroid](/img/e3/4e003f5d89752306ea901c70230deb.png)
[learning notes] matroid

nlp序列完全可以模拟人脑智能

App automated testing appium tutorial 2 - ADB command

MySQL row format parsing

SQL Master slave Replication Build

Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)

B_QuRT_User_Guide(26)

Introduction to Devops Basics

Why MySQL cannot insert Chinese data in CMD
随机推荐
Set the icon for the title section of the page
Introduction to Devops Basics
Upgrade HDP spark to spark 2.4.8 without upgrading ambari
MySQL two table connection principle (understand join buf)
sql分析(查询截取分析做sql优化)
Doris学习笔记之介绍、编译安装与部署
[learning notes] simulation
Redis deployment under Linux & redis startup
MySQL row format parsing
ROS 笔记(08)— 服务数据的定义与使用
Do you know TCP protocol (2)?
nlp序列完全可以模拟人脑智能
Trigonometric transformation formula
Activity隐式跳转
Introduction, compilation, installation and deployment of Doris learning notes
Force buckle 1024 video splicing
Prometheus + grafana + MySQL master-slave replication + host monitoring
sql主从复制搭建
Jenkins' common build trigger and hook services (V)
ROS notes (08) - definition and use of service data