「专题训练」Boredom(CodeForces Round #260 Div.1 A)
题意(Codeforces-455A)
给你\(n\)个数,你每次可以选择删除去一个数\(x\)获得\(x\)分,但是所有为\(x+1\)和\(x-1\)的数都得删去。问最大获得分数。
分析
这是一条经典dp。阶段是很自然的:我从左往右依次选择到每种数(先预处理在桶内),然后两个决策:拿,还是不拿(拿一定拿光)。拿,那么下一步就不能选择\(x+1\)了,直接选择\(x+2\);不拿,我可以选择\(x+1\)。两种情况取最大。
于是有状态转移方程:\(dp[x]=max(dp[x-1], dp[x-2]+x*cnt_x)\)
代码
#include <bits/stdc++.h>
using namespace std;
long long arr[100005], dp[100005];
int main()
{
int n; cin>>n;
memset(arr,0,sizeof(arr));
for(int i=1;i<=n;++i)
{
int tmp; cin>>tmp;
arr[tmp]++;
}
dp[1]=arr[1]; dp[0]=0;
for(int i=2;i<=100000;++i)
{
dp[i]=max(dp[i-1], dp[i-2]+i*arr[i]);
}
cout<<dp[100000]<<endl;
return 0;
}
「专题训练」Boredom(CodeForces Round #260 Div.1 A)的更多相关文章
- 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 ...
- 「专题训练」Hard problem(Codeforces Round #367 Div. 2 C)
题意与分析 题意:给出\(n\)个字符串,可以反转任意串,反转每个串都有其对应的花费\(c_i\).经过操作后是否能满足字符串\(\forall i \in [1,n] \text{且} i \in ...
- 「专题训练」k-Tree(CodeForces Round #247 Div.2 C)
题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2, ...
- 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) 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. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- Codeforces Round #260 (Div. 2)C. Boredom(dp)
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #260 (Div. 1) Boredom(DP)
Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
随机推荐
- ecshop 中如何禁用右键和F12
找到 网站根目录/themes/js/common.js,在最后加入如下代码: //禁用右键和F12 //方法一 document.oncontextmenu = function () { retu ...
- Linux磁盘分区,挂载
分区基础知识 分区的方式: 1) mbr分区: 1.最多支持四个主分区 2.系统只能安装在主分区 3.扩展分区要占一个主分区 4.MBR最大只支持2TB,但拥有最好 ...
- 使用GraphViz画caffe网络结构图
参考http://blog.csdn.net/happynear/article/details/45440709 1. 安装pydot: sudo pip install pydot 2. 安装Gr ...
- Windows 10推送的锁屏壁纸保存方法
Windows 10推送的锁屏壁纸保存方法 工作中使用的系统为Windows 10,锁屏时显示的壁纸很漂亮,并且每天都会更新,有几张特别喜欢,于是就想这些壁纸到底保存在哪里呢?经过一番摸索,终于搞明白 ...
- Deferred Lighting
Deferred lighting separate lighting from rendering and make lighting a completely image-space techni ...
- DBUtils 学习使用
DBUtils 学习使用 commons-dbutils简介 commons-dbutils是Apache组织提供的一个开源JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbuti ...
- 安装psutil时提示缺少python.h头文件(作记录)
通过pip或者源码安装psutil,都会提示缺少python.h头文件,错误提示如下: ... psutil/_psutil_common.c:9:20: fatal error: Python.h: ...
- 【小尝试】Java获取慕课网原有路径课程列表
作为一个老慕课网(https://www.imooc.com/)粉丝,还记得最开始的慕课网有很多免费的路径课程,练习什么的也特别详细,是入门一门语言的好方法. 现在慕课网发展起来了收费模式,添加了很多 ...
- ruby中的return方法及class实例方法的initialize方法
return是函数的返回值 class Mtring def initialize(str) @name = str end def aa ary = @name.split(/:/) return ...
- 第3天 Java基础语法
第3天 Java基础语法 今日内容介绍 引用数据数据类型(Scanner.Random) 流程控制语句(if.for.while.dowhile.break.continue) 引用数据类型 Scan ...