题目传送门

 /*
DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std; typedef long long ll;
const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
ll dp[MAXN][];
ll cnt[MAXN]; ll work(int mx)
{
ll ret = ;
for (int i=; i<=mx; ++i)
{
dp[i][] = dp[i-][] + cnt[i] * i;
dp[i][] = max (dp[i-][], dp[i-][]);
ret = max (ret, dp[i][]);
ret = max (ret, dp[i][]);
} return ret;
} int main(void) //Codeforces Round #260 (Div. 1) A. Boredom
{
int n; scanf ("%d", &n); int mx = ;
for (int i=; i<=n; ++i)
{
int x; scanf ("%d", &x); cnt[x]++;
mx = max (mx, x);
} printf ("%I64d\n", work (mx)); return ;
}

递推DP Codeforces Round #260 (Div. 1) A. Boredom的更多相关文章

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

  2. 【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid

    题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i& ...

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

  4. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

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

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

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

  7. 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland

    题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...

  8. DP Codeforces Round #303 (Div. 2) C. Woodcutters

    题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...

  9. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

随机推荐

  1. 剑客决斗(NYOJ 110)

    T3.题目110剑客决斗 (http://acm.nyist.net/JudgeOnline/problem.php?pid=110) 描述 在路易十三和红衣主教黎塞留当权的时代,发生了一场决斗.n个 ...

  2. HDU 1754_I Hate It

    [题意]给定区间求最大值 [分析]线段树单点更新 [代码] #include<cstdio> #include<iostream> using namespace std; c ...

  3. 【进击后端】Ubuntu 命令行 安装nginx

    一.安装nginx apt-get install nginx 安装路径为:/etc/nginx/conf.d 二.配置nginx,在conf.d目录下新建test.conf 新建文件的命令是vi t ...

  4. CSS实现自适应不同大小屏幕的背景大图的两种方法(转自简书)

    CSS实现自适应不同大小屏幕的背景大图的两种方法 一张清晰漂亮的背景图片能给网页加分不少,设计师也经常会给页面的背景使用大图,我们既不想图片因为不同分辨率图片变形,也不希望当在大屏的情况下,背景有一块 ...

  5. 高数(A)下 第十二章

    12.1 12.2 12.3  12.4 12.5  12.6 自测题

  6. freemarker导出word的一些问题

    首先,了解下freemarker导出word的流程: 参考https://www.cnblogs.com/llfy/p/9303208.html 异常一: freemarker.core.ParseE ...

  7. php-fpm配置项

    php版本:php-7.3 全局配置 ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; ; All relative ...

  8. 【Nginx】epoll及内核源码详解

    内核源码: https://www.nowcoder.com/discuss/26226?type=0&order=0&pos=21&page=1 epoll流程: 首先调用e ...

  9. [Unity3D]Unity3D游戏开发之从Unity3D到Eclipse

    ---------------------------------------------------------------------------------------------------- ...

  10. C++虚函数表剖析

    关键词:虚函数.虚表,虚表指针,动态绑定,多态 一.概述 为了实现C++的多态,C++使用了一种动态绑定的技术. 这个技术的核心是虚函数表(下文简称虚表).本文介绍虚函数表是怎样实现动态绑定的. 二. ...