码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-18 18:21:16      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!