当前位置:网站首页>Codeworks round 693 (Div. 3) C. long jumps problem solution
Codeworks round 693 (Div. 3) C. long jumps problem solution
2022-07-24 16:22:00 【Is_ TuTouYa】
Codeforces Round #693 (Div. 3) C. Long Jumps
The original question is here !
The main idea of the topic
Polycarp Playing a game , Given that there is n Array of elements a, Set a starting point i. When i <= n when , i = i + a[i], score score = score + a[i], Try to find out for the array a The maximum score that can be obtained .
analysis
First of all, this question has a large amount of data , time limit 2s, Violent solution is affirmative ⑧ Yes .
Observe the topic carefully , For each assumed starting value i , There are two cases :
i + a[i] > n , At this time, its score ans = a[i].
i + a[i] <= n , The game is not over i = i + a[i] , score ans += a[i] , And the next round , until i + a[i] > n until .
If we're from i = n To traverse the , And will a[i] Your scores are stored in a[i] in , Even if i + a[i] <= n The situation of , Its a[i+a[i]] Your score has been calculated , You don't need to start from scratch .
The code is as follows
#include<bits/stdc++.h>
using namespace std;
const int N = 2*1e5+10;
int main(){
int t;
cin >> t;
for(int p = 0;p < t;p++){
long long a[N],n,maxn = 0;
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i = n;i > 0;i--){
if(i+a[i]<=n) a[i] += a[i+a[i]];
if(a[i] > maxn) maxn = a[i];
}
cout << maxn << endl;
}
return 0;
}
END
边栏推荐
- [leetcode] day103 search two-dimensional matrix II
- TCP protocol debugging tool tcpengine v1.3.0 tutorial
- Dongfang Guangyi refuted the rumor late at night, saying that the news that the hammer was filed for investigation was untrue!
- With this machine learning drawing artifact, papers and blogs can get twice the result with half the effort!
- 【南京农业大学】考研初试复试资料分享
- G026-db-gs-ins-03 openeuler deployment opengauss (1 active and 2 standby or multiple standby)
- Code shoe set - mt2095 · zigzag jump
- 22 bracket generation
- 安信证券开户在手机开户安全吗?
- Introduction to kettle messy notes
猜你喜欢

Princeton calculus reader 02 Chapter 1 -- composition of functions, odd and even functions, function images

2.19 haas506 2.0开发教程 - bluetooth - 蓝牙通信(仅支持2.2以上版本)

Dedecms editor supports automatic pasting of word pictures

yolov3 训练自己的数据集

31 next spread

【南京农业大学】考研初试复试资料分享

狗牙根植物介绍

电话系统规则

How to choose the appropriate data type for fields in MySQL?

Dynamics 365: how to get the authentication information required to connect to D365 online from azure
随机推荐
There are more than 20 categories of the four operators in MySQL. It took three days and three nights to sort them out. Don't collect them quickly
Qt设计仿真机器人控制器
How to choose the appropriate data type for fields in MySQL?
ARP 入门
【LeetCode】Day103-搜索二维矩阵 II
Due to lack of funds, Changdian technology sold some assets of Xingke Jinpeng for 120million US dollars!
Ligerui table control grid changes the color of rows (cells) according to the content
Enter a URL to this page to show it. What happened in this process?
EC200U-CN模块的使用
.net review the old and know the new: [6] what is LINQ
若依 this.$router.push 同地址不同参,页面不刷新问题
Host PSQL connecting virtual machine Oracle
Software recommendation - website construction
Disassembly of Samsung Galaxy fold: the interior is extremely complex. Is the hinge the main cause of screen damage?
Code shoe set - mt2095 · zigzag jump
Research on the efficiency of numpy array access
TCP protocol debugging tool tcpengine v1.3.0 tutorial
Talk about C pointer
文件浏览器?Qt也可以实现!
31 next spread