CodeForces 456C - Boredom(DP)

CodeForces 455A:Boredom (动态规划) Alex 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. 阅读详情

C. Boredom
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alex 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.

Input

The 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).

Output

Print a single integer — the maximum number of points that Alex can earn.

Examples
Input
2
1 2
Output
2
Input
3
1 2 3
Output
4
Input
9
1 2 1 3 2 2 2 2 3
Output
10
Note

Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.


/*
题目链接: http://codeforces.com/problemset/problem/456/C

题意:给定一个含有n个整数的数组,你可以进行多次操作,每次操作从数组选一个数a[k],
然后将其删除,然后删除与a[k]-1和a[k]+1相等的数,
然后可以得到a[k]分,求进行多次操作后得到的最多的分

DP
先将每个数*这个数的个数,得到选这个数所能得到的分
然后DP,
    dp[i] = max( dp[i-1], 不选i这个数
                 dp[i-2] + val[i] 选i这个数 )

    要注意的是,
    最终的答案不是dp[]这个数组的最后一个值
    而是全部里面最大的那个

HDU 2845 是这个题的升级版
http://acm.hdu.edu.cn/showproblem.php?pid=2845
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 1e5 + 5;
const int N = 1e4 + 5;
const int mod = 1e8;

int a[maxn];
int cnt[maxn];
LL val[maxn], dp[maxn];
int main(void)
{
//	freopen("in.txt","r", stdin);
    int n, maxx;
    while (cin >> n){
        memset(cnt, 0, sizeof(cnt));
        memset(dp, 0, sizeof(dp));
        maxx = -1;
        for (int i = 1; i <= n; i++){
            cin >> a[i];
            cnt[a[i]]++;
            maxx = max(maxx, a[i]);
        }
        for (int i = 1; i <= maxx; i++)
            val[i] = (LL)cnt[i] * (LL)i;
        memset(dp, 0, sizeof(dp));
        dp[1] = val[1];
        for (int i = 2; i <= maxx; i++)
            dp[i] = max(dp[i-1], dp[i-2]+val[i]);
        LL ans = -1;
        for (int i = 1; i <= maxx; i++)
            ans = max(ans, dp[i]);
        cout << ans << endl;
    }

	return 0;
}







SAP-ABAP:SAP Open SQL 分页技术深度解析:语法、性能陷阱与最佳实践 SAP Open SQL 分页技术深度解析:语法、性能陷阱与最佳实践 阅读详情

相关推荐

深入理解HanLP1.x,填平可能遇到的坑

提取指定数量的摘要。自定义词典为什么要单独领出来讲呢?因为在我们的业务开发中,可能分词的效果并不理想,需要定制自己的词库,索引更加常用。例如:小米su7特斯拉modelY比亚042025款6575767670908我们需要分出小米su72025款等词。我们分别看看用字典和不用字典的效果。

static_coder的博客 986

Codeforces 455A. Boredom [ 简单DP ]

A. Boredomtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One...

howell 436

Arduino MLX90393磁力计驱动库:高精度三轴霍尔传感器开发指南

三轴霍尔效应磁力计是嵌入式系统中实现无接触角度检测、电子罗盘与电流传感的核心器件。其工作原理基于霍尔电压随外磁场矢量变化的物理特性,通过I²C接口输出高分辨率(16/20-bit)XYZ轴原始数据,并集成温度补偿与数字滤波功能。技术价值体现在确定性响应、低功耗(典型0.5 μA待机)及强抗干扰能力,适用于电池供电设备与实时操作系统环境。典型应用场景包括电机位置反馈、永磁体旋转角度解算、工业编码器和地磁导航。本库专为Arduino生态优化,深度封装MLX90393寄存器协议与自校准流程,同时兼容STM32、E

weixin_29363791的博客 650

A. Boredom

A. Boredom Alex 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 sin

tatan_的博客 265

基于STM32的INA226电压电流检测仪

该功率检测装置以STM32F103C8T6微控制器为核心,集成功率检测、数据交互、状态显示和用户提示功能,通过模块化设计实现稳定运行。系统包括按键、LED指示灯、OLED屏幕、INA226电压电流检测、复位电路、晶振电路、蜂鸣器驱动、输入输出接口、调试接口和3.3V降压电路等模块。微控制器通过按键检测用户输入,启动功率检测,采集数据并通过OLED显示,异常情况触发蜂鸣器报警,LED状态指示同步反馈。3.3V降压电路为所有模块提供稳定电源,晶振电路确保时序精度。INA226芯片通过I2C接口与微控制器通信,实

a2784288164的博客 1922

微信小程序真机HTTPS证书链失效排查与修复指南

HTTPS证书信任链是保障Web通信安全的基础机制,其核心在于客户端能否通过服务器提供的证书及其上级签发者,逐级回溯至自身预置的可信根证书。在微信小程序场景中,由于客户端不复用系统根证书库,而是采用固化、精简且更新滞后的自研CA白名单,导致大量符合浏览器标准的证书(如Let’s Encrypt新版ISRG Root X1、TrustAsia等)在真机环境下触发net::ERR_CERT_AUTHORITY_INVALID错误。该问题本质是证书链断裂或签名算法/密钥长度不合规,而非域名配置或CORS策略异常。

weixin_33935636的博客 692

[CodeForce455A]Boredom

题面描述 Alex 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. 亚历克斯不喜欢无聊。这就是为什么每当他感到无聊时,他就会想出一些游戏。在一个...

weixin_34023863的博客 260

SAP-ABAP:SAP信贷管理核心:CL_UKM_BUPA_FACTORY类完整解析与实践指南

SAP信贷管理核心类CL_UKM_BUPA_FACTORY解析 CL_UKM_BUPA_FACTORY是SAP信贷管理(UKM)模块的核心类,作为业务伙伴信贷数据的中央控制台,它提供: 统一入口:标准化实例化客户/供应商信贷对象 主要功能: 获取单条/批量业务伙伴数据 安全保存数据变更 封装底层数据访问逻辑 典型应用场景: 信贷主数据批量维护 自动化限额调整 订单信贷实时检查 性能优化建议: 使用批量方法替代循环单条处理 合理设置字段选择 实施缓存策略 该类通过简洁API简化复杂信贷操作,是SAP信贷管理开

baidu_35680696的博客 1222

CodeForces_455A Boredom ( 基础dp )

文章目录题意题解代码 题目连接 vj or cf 题意 题解 代码

♡ 脚下的每一步都叫远方 ♡ 294

ABAP 百科全书的阅读目录(2024版)

909 篇 ABAP 技术文章的目录

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 4261

2025年开源气象大模型的实现原理与实践指南

气象大模型在人工智能时代实现了革命性突破,通过深度学习技术以更低的计算成本达到甚至超越传统数值天气预报的精度。开源气象大模型的出现使得全球研究者和机构都能参与气象AI的创新。本文详细解析了开源气象大模型的实现原理,包括核心架构、数据准备、训练方法和实际预测流程,并提供了实践指南。核心架构主要采用Transformer、图神经网络和扩散模型,处理多模态数据融合和时空联合建模。数据体系构建涉及数据来源、预处理和增强策略。模型训练关键技术包括损失函数设计、分布式训练优化和训练过程监控。微调与领域适应策略包括迁移学

专注AI大模型,软件混淆,授权 1198

Codeforces 456C Boredom DP

点击打开链接 题意:n 想一想 二分贪心和构造好像都用不上 a[i] dp[i] 当前删除的最大数字为i时得到的最大得分  dp[i]=max(dp[i-2]+i*mp[i],dp[i-1]);//i被i-1间接删除 或者 亲自删除i(由dp[i]定义得dp[i]>=dp[i-1],i存在时的最大得分为dp[i-2])  #include using namespace std;

Masamiiiiii 407

(王道考研计算机网络)第三章数据链路层-第一节:数据链路层功能概述

文章目录一:本章概述二:数据链路层基本概念三:数据链路层功能概述(1)为网络层提供服务(2)链路管理(3)组帧(4)流量控制(5)差错控制 本章是计算机网络中入门较难的一章,如果没有接触过相关内容,可能会止步于一些晦涩难懂的术语。本节内容希望大家可以用心看一看,对于大家入门是很有帮助的 一:本章概述 数据链路层位于物理层之上,主要作用就是提高物理层传输比特流的能力,使物理层可能出现差错的连接转变为逻辑上无差错的数据链路,同时向网络层提供服务。本章学习的主要就是数据链路层的功能和应用 数据链路层功能 封

快乐江湖的博客 2479

CodeForces - 456C Boredom(线性dp)

题目链接:点击查看 题目大意:给出一个由n个数字组成的数列,现在给出规则是,每次选择数列中的一种数字 x,选择后的贡献为 x,不过操作后会删除掉所有数值为 x + 1 和 x - 1 的数,现在问如何选择可以使得贡献最大 题目分析:线性dp,因为每个数若选择的话,那么他前后两个数都无法选择了,我们可以直接视为相邻两个数的关系,若当前的数选了,那么前一个数就没法选,若当前的数不选,则前一个数是可...

Falcon的博客 627

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

CodeForces - 456C Boredom (dp)

题目大意:        给定一个含有n个整数的数组,你可以进行多次操作,每次操作从数组选一个数a[k],然后将其删除,然后删除与a[k]-1和a[k]+1相等的数,然后可以得到a[k]分,求进行多次操作后得到的最多的分。 题解:       设dp[i]表示当前删除的最大数字为i时得到的最大得分        dp[i]=max(dp[i-1],dp[i-2]+i*num[i]);  ...

hxxjxw的博客 458

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【题解】【DP专题】Codeforces 456C Boredom(线性DP)

可以从1枚举到全部数的最大值,枚举到一个数考虑要不要这个数,如果要这个数那么前面一个数就不能要,不要这个数就是前面的前面的最大值转移过来,大概考虑一下就可以发现题目中的删掉a+1这个数其实不必考虑,具体看代码。给你n个数让你删掉一些数,例如删掉a你可以获得a分,但是a+1, a-1的数也会被删除,问你可以获得的最大分数是多少.

wdnxmd的博客 160

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Codeforces 456C - Boredom(简单DP)

Alex 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 sequenceaconsistin...

weixin_34021089的博客 211

Codeforces 456C Boredom

目录知识点:线性dp(递推)、贪心题目输入输出样例输入1输出1输入2输出2输入3输出3提示题意思路代码 知识点:线性dp(递推)、贪心 题目 Alex 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 consistin

夏午Sharve的博客? 388

codeforces #260 DIV 2 C题Boredom(DP)

题目地址:http://codeforces.com/contest/456/problem/C 脑残了。。DP只DP到了n。。应该DP到10w+的。。 代码如下: #include #include #include #include #include #include #include #include #include #include #include usi

scf0920 2319

CodeForces 456-C Boredom

题目链接:CodeForces -456C Description Alex 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 ...

weixin_30470857的博客 232

codeforces_456C_dp

链接:http://codeforces.com/problemset/problem/456/C C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex d...

weixin_34146986的博客 108

Codeforces Round #260 (Div. 2)

A. Laptopshttp://codeforces.com/contest/456/problem/A 1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 const int M=100010; 5 struct G{ 6 int x,y;...

102

Codeforces 260 C. Boredom

题目链接:http://codeforces.com/contest/456/problem/C 解题报告:给出一个序列,然后选择其中的一个数 k 删除,删除的同时要把k - 1和k + 1也删除掉,同时总分数里面加上一个k,求最大的分数可以是多少? dp题,递推公式是 dp[i] = max(dp[i-2]+num[i] * i,dp[i-1]); ,注意要用long long ,一开始...

weixin_30405421的博客 88

Boredom(线性DP,状态机)

DP

zydzyd521的博客 323

codeforces455——A. Boredom(线性DP)

原题链接 题意: 思路: 记录每个数的出现次数为a[i]。 考虑dp。 dp[i][j]表示选到i并且i的状态为j的最大价值。 当j==0时,表示不选i,此时i-1选不选都可以。 当j ==1时,表示选i,这时候i-1必须不选,选i的贡献是i*a[i]。 遍历到1e5就好了。 也可以将第二维去掉。 代码: #pragma GCC optimize(3) #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") #p

我们都有光明的未来 451
上一篇: HDU 5723 - Abandoned country(最小生成树+dfs)
下一篇: HDU 5934 Bomb(强连通缩点)
Waves___
博客等级 码龄10年 84粉丝 142原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值