2021-7-17 Boredom
2021/7/17 23:13:46
本文主要是介绍2021-7-17 Boredom,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
难度 1500
题目 CodeForces:
Boredom time limit per test 1 second memory limit per test 256 megabytesAlex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
InputThe first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105).
OutputPrint a single integer — the maximum number of points that Alex can earn.
KeyWord
boredom 无聊
perfectionist 完美主义者
题目解析
本题大意是对给出的n个数进行操作,使得最后得到的分数尽可能高,操作包括去掉一个元素,然后去掉数组内等于该元素-1和+1的所有元素,并使分数加上该元素的值。
这题是简单的dp,所以直接看代码
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll x[100005] = { 0 }, y[100005] = { 0 }; ll n,ans; int main() { cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; x[t]++; } y[0] = 0; y[1] = x[1]; for (int i = 2; i < 100005; i++) { y[i] = max(y[i - 1], y[i - 2] + x[i] * i); ans = max(ans, y[i]); } cout << ans<<endl; return 0; }
这篇关于2021-7-17 Boredom的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16使用vue3+springboot构建简单Web应用教程
- 2024-11-15全栈开发项目实战:从入门到初级项目的实现
- 2024-11-15数据库项目实战:从入门到初级应用教程
- 2024-11-15IDEA项目实战入门教程
- 2024-11-15IT编程项目实战:新手入门的全面指南
- 2024-11-15Java开发项目实战:新手入门与初级技巧
- 2024-11-15Java零基础项目实战:从入门到独立开发
- 2024-11-15MyBatis Plus教程:入门与基础操作详解
- 2024-11-15MyBatis-Plus教程:新手入门与实战技巧
- 2024-11-15MyBatis教程:从入门到实践