Coderforces-455A
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.
Example
2
1 2
2
3
1 2 3
4
9
1 2 1 3 2 2 2 2 3
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.
题意:就是给你N个数。你可选择大小的为A的数,但是A-1和A+1必须从数队移走。
题解:本题与数的顺序无关(这时候想到了DP),我们先对其排序。然后找其状态转移方程。假设dp[j]表示从1加到j 时最大值。则dp[j]=max(dp[j-1],dp[j-2]+i*cnt[i]).【ps:cnt[i]表示数值为】
AC代码为:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long n, a[100002], cot[100002], d[100002];
int main()
{
cin >> n;
long long Max = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] > Max)
Max = a[i];
cot[a[i]]++;
}
d[1] = cot[1]; d[0] = 0;
for (int i = 2; i <= Max; i++)
d[i] = max(d[i - 1], d[i - 2] + cot[i] * i);
cout << d[Max] << endl;
return 0;
}
Coderforces-455A的更多相关文章
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- coderforces #384 D Chloe and pleasant prizes(DP)
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- coderforces 731c
题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...
- coderforces 721b
题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CoderForces 280B(记忆化搜索)
题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...
- CodeForces 455A Boredom (DP)
Boredom 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/G Description Alex doesn't like b ...
- Codeforces 455A Boredom (线性DP)
<题目链接> 题目大意:给定一个序列,让你在其中挑选一些数,如果你选了x,那么你能够得到x分,但是该序列中所有等于x-1和x+1的元素将全部消失,问你最多能够得多少分. 解题分析:从小到大 ...
- Codeforces 455A - Boredom - [DP]
题目链接:https://codeforces.com/problemset/problem/455/A 题意: 给出一个 $n$ 个数字的整数序列 $a[1 \sim n]$,每次你可以选择一个 $ ...
- CF 455A Boredom
A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
随机推荐
- Flink入门(一)——Apache Flink介绍
Apache Flink是什么? 在当代数据量激增的时代,各种业务场景都有大量的业务数据产生,对于这些不断产生的数据应该如何进行有效的处理,成为当下大多数公司所面临的问题.随着雅虎对hadoop的 ...
- Docker学习-Docker搭建Consul集群
1.环境准备 Linux机器三台 网络互通配置可以参考 https://www.cnblogs.com/woxpp/p/11858257.html 192.168.50.21 192.168.50.2 ...
- [error]The command could not be located because '/usr/bin' is not included
配置HBase环境变量的时候写错了,写成了如下: 之后便报错 解决: 系统命令找不到时,通常是路径不对,直接在命令行用全路径即可,配置环境变量时,加入自己的环境变量,还要附带上之前的变量.如最后加上: ...
- spring源码1
1.beans核心类 1.DefaultListableBeanFactory xmlBeanFactory xmlBeanFactory继承自DefaultListableBeanFactory,D ...
- suseoj 1209: 独立任务最优调度问题(动态规划)
1209: 独立任务最优调度问题 时间限制: 1 Sec 内存限制: 128 MB提交: 3 解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 用2台处理机A和B处理 ...
- nyoj 103-A+B Problem II (python 大数相加)
103-A+B Problem II 内存限制:64MB 时间限制:3000ms 特判: No 通过数:10 提交数:45 难度:3 题目描述: I have a very simple proble ...
- vue cli3.0 封装组件全局引入js文件并发布到npm
首先用 vue create创建一个项目 当前的项目目录是这样的: 首先需要创建一个 packages 目录,用来存放组件 然后将 src 目录改为 examples 用作示例 二.修改配置 启动项目 ...
- 真的,Kafka 入门一篇文章就够了
初识 Kafka 什么是 Kafka Kafka 是由 Linkedin 公司开发的,它是一个分布式的,支持多分区.多副本,基于 Zookeeper 的分布式消息流平台,它同时也是一款开源的基于发布订 ...
- 1sql
------------------ MySQL 服务-- sudo service mysql start/stop/restart/status ------------------ 数据库相关的 ...
- day20191012笔记
课程默写笔记: 1.程序架构 C/S 客户端/服务器端 B/S 浏览器/服务器端 2.Tomcat应用服务器 tomcat默认端口号是80:tomcat配置文件中通常端口的定义是8080: 3.使用开 ...