题目链接:http://codeforces.com/problemset/problem/455/A

给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少。

简单dp,dp[i]表示取i时zui最大和为多少,方程为dp[i] = max(dp[i - 1] , dp[i - 2] + cont[i]*i)。

 #include <bits/stdc++.h>
using namespace std;
typedef __int64 LL;
const int MAXN = 1e5 + ;
LL a[MAXN] , cont[MAXN] , dp[MAXN];
int main()
{
int n;
scanf("%d" , &n);
for(int i = ; i <= n ; ++i) {
scanf("%lld" , a + i);
++cont[a[i]];
}
dp[] = cont[] * ;
for(int i = ; i <= 1e5 ; ++i) {
dp[i] = max(dp[i - ] , dp[i - ] + cont[i] * i);
}
printf("%lld\n" , dp[int(1e5)]);
return ;
}

Codeforces Round #260 (Div. 1) A. Boredom (简单dp)的更多相关文章

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

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

  3. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

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

  5. dp解Codeforces Round #260 (Div. 2)C. Boredom

    #include<iostream> #include<map> #include<string> #include<cstring> #include ...

  6. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  7. Codeforces Round #113 (Div. 2) Tetrahedron(滚动DP)

    Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  8. Codeforces Round #119 (Div. 2) Cut Ribbon(DP)

    Cut Ribbon time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

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

随机推荐

  1. bzoj4011

    好题,首先有一个结论,有向无环图的树形图数目=根节点意外入度之积 现在相当于在原图上加一条边问树形图的数目 考虑多出来不合法的方案,一定是成环且包含新加入的边 对于一条路贡献就是∏d[i] [i∉pa ...

  2. springMVC传对象参数、返回JSON格式数据

    假如请求路径:http://localhost/test/test.do?user.id=1 后台接收参数的方法如下: @RequestMapping("/test") publi ...

  3. 为初学者写ORM,ORM的原理及测试案例

    提纲 一.什么是ORM.二.反射以及Attribute在ORM中的应用.三.创建一个数据库表和表对应的实体model.四.实体model如何映射出数据库表.五.组合ORM映射生成insert语句.六. ...

  4. iOS 静态类库项目的建立与使用

    iOS 静态类库项目的建立与使用   新建 Xcode workspace 打开 Xcode , 选择 File -> New -> Workspace , 将 Workspace 命名为 ...

  5. https实现安全传输的流程

    HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL / TLS,也就是在HTTP上又加了一层处理加密信息的模块.服务端和客户端的信息传输都会通过TLS进行加密,所以传输的数据都是加密后 ...

  6. shell 删除日志

    一般线上服务的日志都是采用回滚的防止,写一定数量的日志 或是有管理工具定期去转移老旧日志 前几天删除一个测试环境的日志,只保留两天的日志,结果把正在写的日志都给删掉了,不得不重启了服务,经过这一次的错 ...

  7. 图片鼠标滑过图片半透明(jquery特效)

    在做瑞祥之旅的过程,有一个部分是材料体系,材料体系下面.预览效果

  8. Python easy_install

    系统中有高版本的Python, 直接pip3 install ipcalc安装,都是装到高版本的Python 系统默认的Python是2.7.6,现在想装到默认版本中,可以使用easy_install ...

  9. C# Code for Downloading Stock Symbols z

    http://www.jarloo.com/download-stock-symbols/ If your using C# you can easily get the XML data using ...

  10. [Java]读取文件方法大全

    1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 , byteread);             }         } catch (IOException  ...