455A Boredom
来源:互联网 发布:知其所以然的意思 编辑:程序博客网 时间:2024/04/30 01:14
简单DP。
#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <string>#include <vector>#include <deque>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <algorithm>#include <functional>using namespace std;const int maxn = 100010;typedef long long ll;ll arr[maxn], dp[maxn];ll v[maxn], c[maxn];ll min(ll a, ll b) { return a < b ? a : b;}ll max(ll a, ll b) { return a > b ? a : b;}int main() { int n, m = 0; scanf("%d", &n); for(int i = 1; i <= n; ++i) { cin >> arr[i]; } sort(arr + 1, arr + n + 1); arr[0] = 0; for(int i = 1; i <= n; ++i) { if(arr[i] != arr[i-1]) { v[++m] = arr[i]; c[m] = 1; } else { c[m]++; } } dp[0] = 0; c[0] = 0; dp[1] = v[1] * c[1]; for(int i = 2; i <= m; ++i) { if(v[i] == v[i-1] + 1) { if(v[i-2] + 1 == v[i-1]) { ll t = v[i-1] * c[i-1]; if(i >= 3) { t += dp[i-3]; } dp[i] = max(dp[i-2] + v[i] * c[i], t); } else { dp[i] = max(dp[i-2] + v[i-1]*c[i-1], dp[i-2] + v[i]*c[i]); } } else { dp[i] = dp[i-1] + v[i] * c[i]; } } cout << dp[m] << endl; return 0;}
0 0
- codeforces 455A Boredom
- CodeForces 455A Boredom
- 455A Boredom
- 455A - Boredom
- CodeForces 455A - Boredom
- CodeForces 455A Boredom
- Codeforces-455A-Boredom
- codeforces 455A Boredom dp
- Codeforces 455A Boredom(高效)
- CF 455A(Boredom-dp)
- 【dp】 codeforces 455A Boredom
- Codeforces 455A Boredom (dp)
- CodeForces 455A Boredom (dp)
- Codeforces 455A Boredom【dp】
- codeforces Boredom 455A dp
- A. Boredom
- A. Boredom
- 【CodeForces 455A】Boredom(dp)
- ajax 的两种方式
- Android调用天气预报所对应的城市Id
- ubuntu12.4交叉编译vlc2.2.1的经历
- 解决Fragment中使用ViewPager时,ViewPager里的Fragment错位和空白问题。
- EndNote导入万方论文方法
- 455A Boredom
- C实现 LeetCode->3Sum
- 常用网站
- 适配器详解
- JAVA -- Exception 类型
- 编写语法分析程序
- 第三章 30题
- 使用Pyjnius 从python调用自定义Java方法
- 谷歌国内镜像地址