#260 (div.1) A.Boredom

1.题目描述:点击打开链接

2.解题思路:本题属于01背包型的dp问题。为了使得问题变得便与思考,我们可以顺序考虑每一个数字。事先用数组cnt统计输入的数字的个数。接下来,考虑数字i。如果选择删除它的话,由于是按顺序考虑的,因此所有的i-1都将被删去,那么分数为d[i]+i*cnt[i];如果不删除它,那么分数就是d[i-1]。只需要取较大者即可。

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define me(s) memset(s,0,sizeof(s))
#define For(i,n) for(int i=0;i<(n);i++)

#define MAX 1000005
int a[MAX];
ll d[MAX];
int cnt[MAX];
int n;

int main()
{
	//freopen("t.txt", "r", stdin);
	while (cin >> n)
	{
		me(a); me(d); me(cnt);
		int maxd = 0;
		For(i, n)
		{
			cin >> a[i];
			maxd = max(maxd, a[i]);
			cnt[a[i]]++;
		}
		ll ans = 0;
		d[1] = cnt[1];
		for (int i = 1; i <= maxd; i++)
		{
			if(i>1)d[i] = d[i - 1];
			if (i - 2 >= 0)
				d[i] = max(d[i], d[i - 2] + (ll)i*cnt[i]);
			ans = max(ans, d[i]);
		}
		cout << ans << endl;
	}
	return 0;
}
时间: 2024-11-10 01:12:42

#260 (div.1) A.Boredom的相关文章

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

递推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

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&

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

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