codeforces-455A
题目连接:http://codeforces.com/contest/455/problem/A
1 second
256 megabytes
standard input
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.
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.
题目大意:有n个数,选择一个(设为ak)删除可以得ak分,但是数列中所有等于ak+1或ak-1的数必须删去,求最多可以得多少分。
很典型的dp题目,我比较菜所以状态设置为比较好理解的 dp[i][0]代表不选i的最大值,dp[i][1]代表选i得到的最大值。
转移方程就很好写了,边界也很清晰,详见代码
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- LL dp[][];
- LL c[]={};
- int main()
- {
- int n;
- int in;
- ;
- cin>>n;
- ;i<n;i++)
- {
- scanf("%d",&in);
- c[in]++;
- z=max(z,in);
- }
- memset(dp,,sizeof(dp));
- ;i<=z;i++)
- {
- dp[i][]=dp[i-][]+c[i]*LL(i);
- dp[i][]=max(dp[i-][],dp[i-][]);
- }
- cout<<max(dp[z][],dp[z][]);
- }
codeforces-455A的更多相关文章
- Codeforces 455A - Boredom - [DP]
题目链接:https://codeforces.com/problemset/problem/455/A 题意: 给出一个 $n$ 个数字的整数序列 $a[1 \sim n]$,每次你可以选择一个 $ ...
- 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
题目链接:点击打开链接 给定一个n长的序列 删除x这个数就能获得x * x的个数 的分数,然后x+1和x-1这2个数会消失.即无法获得这2个数的分数 问最高得分. 先统计每一个数出现的次数.然后dp一 ...
- dp学习笔记(各种dp,比较杂)
HDU1176 中文题意不多解释了. 建一个二维dp数组,dp[ i ][ j ]表示第 i 秒落在 j 处一个馅饼.我们需要倒着DP,为什么呢,从 0秒,x=5处出发,假如沿数组正着往下走,终点到哪 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- sql 先查出已知的数据或者需要的数据再筛选
sql 先查出已知的数据或者需要的数据再筛选
- 洛谷 P3084 [USACO13OPEN]照片Photo 解题报告
[USACO13OPEN]照片Photo 题目描述 农夫约翰决定给站在一条线上的\(N(1 \le N \le 200,000)\)头奶牛制作一张全家福照片,\(N\)头奶牛编号\(1\)到\(N\) ...
- eclipse安装反编译插件jadclipse
下载jadClipse地址: 目的:将一些封装的jar或者sdk可以查看源代码 链接: http://pan.baidu.com/s/1kTN4TPd 提取码: 3fvd 将net.sf.jadcl ...
- 如何在plsql/developer的命令窗口执行sql脚本
在plsql/developer的命令窗口执行sql脚本的命令是@+路径 示例如下: 第一步:在C:\Users\linsenq\Desktop目录下新建一个脚本文件: test.sql test.s ...
- wget、yum、rpm、apt-get区别
wget 类似于迅雷,是一种下载工具, 通过HTTP.HTTPS.FTP三个最常见的TCP/IP协议下载,并可以使用HTTP代理 名字是World Wide Web”与“get”的结合. yum: 是 ...
- JS表单验证优化
var validate = (function(){ var messages = { isEmail : '输入正确格式邮箱', isPhoneNum : '输入正确手机号' }; var val ...
- struts学习笔记(四)
一. 文件的上传: 1). 表单需要注意的 3 点 2). Struts2 的文件上传实际上使用的是 Commons FileUpload 组件, 所以需要导入 commons-fileupload- ...
- 【bzoj3926- [Zjoi2015]诸神眷顾的幻想乡】广义sam
题意:给定一棵树,每个节点有一个颜色,问树上有多少种子串(定义子串为某两个点上的路径),保证叶子节点数<=20.n<=10^5 题解: 叶子节点小于等于20,考虑将每个叶子节点作为根把树给 ...
- 【BZOJ3450】Easy [期望DP]
Easy Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 某一天WJMZBMR在打osu~~ ...
- phpcms v9 后台添加修改页面空白页问题解决方法
phpcms v9 添加修改页面空白页的解决方法 找一个正常运行的phpcms 将caches\caches_model\caches_data 目录下的 content_form.class.php ...