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

题目传送门

 1 /*
 2     题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数
 3     DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) i * cnt[i]);
 4         只和x-1,x-2有关,和顺序无关,x-1不取,x-2取那么累加相同的值,ans = dp[mx]
 5 */
 6 #include <cstdio>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <iostream>
10 #include <cmath>
11 using namespace std;
12
13 typedef long long ll;
14 const int MAXN = 1e5 + 10;
15 const int INF = 0x3f3f3f3f;
16 ll dp[MAXN];
17 int cnt[MAXN];
18
19 int main(void)        //Codeforces Round #260 (Div. 1) A. Boredom
20 {
21     int n;
22     while (scanf ("%d", &n) == 1)
23     {
24         memset (dp, 0, sizeof (dp));
25         memset (cnt, 0, sizeof (cnt));
26
27         int x, mx = 0;
28         for (int i=1; i<=n; ++i)    {scanf ("%d", &x);    cnt[x]++;    if (mx < x) mx = x;}
29
30         dp[1] = cnt[1];
31         for (int i=2; i<=mx; ++i)
32         {
33             dp[i] = max (dp[i-1], dp[i-2] + (ll) i * cnt[i]);
34         }
35
36         printf ("%I64d\n", dp[mx]);
37     }
38
39     return 0;
40 }
41
42
43
44 /*
45 2
46 1 2
47 3
48 1 2 3
49 9
50 1 2 1 3 2 2 2 2 3
51 */
时间: 2024-10-12 22:22:43

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

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

题目传送门 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

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

题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with

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

#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; lo

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

题目链接: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). 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef __int64 LL;

Codeforces Round #260 (Div. 2)C. Boredom

题意:N个数,我们可以选择某个数A,然后去掉A,和等于A+1,A-1的所有数字,得到A价值,问最后价值最大 思路:我们可以得到去掉A,得到的价值为A*A的个数,那么dp[i]=max(dp[i]+dp[i-2],dp[i-1]).记得开long long , 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll a[100005]; 5 ll dp[100005]; 6 map<ll ,

Codeforces Round #260 (Div. 2)

A. Laptops 题目意思: 给定n台电脑,第i台电脑的价格是ai ,质量是bi ,问是否存在一台电脑价格比某台电脑价格底,但质量确比某台电脑的质量高,即是否存在ai < aj 且 bi > bj ? 解题思路: 这题一定要看题目,a都是1~n的不同数,b也是1~n的不同数,此题只需要判断ai 是否等于bi ,如果ai != bi 的话,则输出“Happy Alex”,如果所有的ai  == bi 则输出“Poor Alex” 证明:先将a按照从小到大排序,当i<j时ai <

Codeforces Round #260 (Div. 2) ABCDE

A题逗比了,没有看到All ai are distinct. All bi are distinct. 其实很水的.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 #define mnx 100002 8 9 10 struct latop{ 11 int p, q; 12 bo

Codeforces Round #260 (Div. 2) A. Laptops(简单题)

题目链接:http://codeforces.com/problemset/problem/456/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops.

Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环节)

题目链接:http://codeforces.com/problemset/problem/456/B B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fedya studies in a gymnasium. Fedya's maths hometask is to calculate t