标签:
1 /*
2 DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值
3 */
4 #include <cstdio>
5 #include <algorithm>
6 #include <cmath>
7 #include <cstring>
8 using namespace std;
9
10 typedef long long ll;
11 const int MAXN = 1e5 + 10;
12 const int INF = 0x3f3f3f3f;
13 ll dp[MAXN][2];
14 ll cnt[MAXN];
15
16 ll work(int mx)
17 {
18 ll ret = 0;
19 for (int i=1; i<=mx; ++i)
20 {
21 dp[i][1] = dp[i-1][0] + cnt[i] * i;
22 dp[i][0] = max (dp[i-1][0], dp[i-1][1]);
23 ret = max (ret, dp[i][0]);
24 ret = max (ret, dp[i][1]);
25 }
26
27 return ret;
28 }
29
30 int main(void) //Codeforces Round #260 (Div. 1) A. Boredom
31 {
32 int n; scanf ("%d", &n);
33
34 int mx = 0;
35 for (int i=1; i<=n; ++i)
36 {
37 int x; scanf ("%d", &x); cnt[x]++;
38 mx = max (mx, x);
39 }
40
41 printf ("%I64d\n", work (mx));
42
43 return 0;
44 }
递推DP Codeforces Round #260 (Div. 1) A. Boredom
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4657232.html