Codeforces Round #260 (Div. 2) C
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 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.
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).
Print a single integer — the maximum number of points that Alex can earn.
2
1 2
2
3
1 2 3
4
9
1 2 1 3 2 2 2 2 3
10
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,并且n-1,n+1也删除,我们要获得n的总和要最大
解法:DP,我们记录每个数字出现次数,这样删除之后还能乘以i得到一个和,我们还要把最大的数字找出来
这样我们就从2—>max 有dp[i]=dp[i-1],因为i-1也要删除的,dp[i]=dp[i-2]+i*出现次数,求他们之间的最大值
注意起始dp[0],dp[1]
#include<bits/stdc++.h>
using namespace std;
map<long long,long long>q;
long long dp[100010];
int main()
{
long long n;
long long m;
long long MAX=-1;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>m;
q[m]++;
MAX=max(MAX,m);
}
dp[0]=0;
dp[1]=q[1];
for(int i=2;i<=MAX;i++)
{
dp[i]=max(dp[i-1],(long long)(dp[i-2]+i*q[i]));
}
cout<<dp[MAX]<<endl;
return 0;
}
Codeforces Round #260 (Div. 2) C的更多相关文章
- DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...
- 递推DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...
- Codeforces Round #260 (Div. 2)AB
http://codeforces.com/contest/456/problem/A A. Laptops time limit per test 1 second memory limit per ...
- Codeforces Round #260 (Div. 1) D. Serega and Fun 分块
D. Serega and Fun Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/pro ...
- Codeforces Round #260 (Div. 1) C. Civilization 并查集,直径
C. Civilization Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/probl ...
- Codeforces Round #260 (Div. 1) A - Boredom DP
A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)
题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...
- Codeforces Round #260 (Div. 2)
A. Laptops 题目意思: 给定n台电脑,第i台电脑的价格是ai ,质量是bi ,问是否存在一台电脑价格比某台电脑价格底,但质量确比某台电脑的质量高,即是否存在ai < aj 且 bi & ...
随机推荐
- ui方案设计
最近在做一个ui,前端,为了引出创意,万事开头难,记录一下: 算是单页吧,一般都是左侧是导航,右边是内容,单页的话,要记录标签关闭,窗口区域. 操作的连惯性等.UI设计是个细活,需要深加研究,以后补充 ...
- HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)
Problem Description Josh Lyman is a gifted painter. One of his great works is a glass painting. He c ...
- Linux内核之旅 链表实现
#include "stdio.h" #include "stdlib.h" struct list_head{ struct list_head *prev; ...
- paper 76:膨胀、腐蚀、开、闭运算——数字图像处理中的形态学
膨胀.腐蚀.开.闭运算是数学形态学最基本的变换.本文主要针对二值图像的形态学膨胀:把二值图像各1像素连接成分的边界扩大一层(填充边缘或0像素内部的孔):腐蚀:把二值图像各1像素连接成分的边界点去掉从而 ...
- paper 58 :机器视觉学习笔记(1)——OpenCV配置
开始学习opencv! 1.什么是OpenCV OpenCV的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可 ...
- app_field.clear_dependent_fields
可以调用APP_FIELD.clear_dependent_fields和APP_FIELD.set_dependent_field来将两个(或多个)Item建立关联,当一个为空时,另一个不可录入,反 ...
- 使用Graham扫描法求二维凸包的一个程序
#include <iostream> #include <cstring> #include <cstdlib> #include <cmath> # ...
- mysql中查询值为NULL的记录
例如表A中的user_login_name的值为NULL,用mysql语句把这条记录查询出来,用select user_login_name from A where user_login_name ...
- ReportingService 通过RowNumber函数获取行号和生成隔行变色样式
以前一直没有搞明白SSRS里面的RowNumber函数到底该怎么用,所以一直没有很好的办法在SSRS中的表格上实现隔行变色的样式,实现隔行变色的关键就是获取表格中每一行的行号.在最近了解了下这个函数, ...
- 50136142WXY的百度地图
50136142WXY的百度地图 [试题描述] 社团里的WXY童鞋今天要出去旅游啦(他现在在北京为1号城市),决定去朝鲜平壤(N号城市).但是很穷的WXY没有钱坐飞机,只好坐汽车去朝鲜了.但是车上的百 ...