C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么:

if(a[i] != a[i-1]+1)   dp[i] = cnt[a[i]]*a[i] + dp[i-1];

else      dp[i] = dp[i] = max(dp[i-1],a[i]*cnt[a[i]] + dp[i-2]),    dp[i-1]表示不取a[i], a[i]*cnt[a[i]] + dp[i-2]表示取a[i].

cnt[a[i]]是a[i]出现的次数。

#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long int a[100010], dp[100010], cnt[100010];
int main(){
int n,num(0);
scanf("%d", &n);
for(int i = 0;i < n;i ++) cin >> a[i];
sort(a, a+n);
for(int i = 0;i < n;i ++) cnt[a[i]] ++;
for(int i = 1;i < n;i ++) if(a[i] != a[i-1]) a[++num] = a[i];
if(num == 0){
cout << a[0]*cnt[a[0]] << endl;
return 0;
}
dp[0] = a[0]*cnt[a[0]];
if(a[0] != a[1]-1) dp[1] = a[0]*cnt[a[0]] + a[1] * cnt[a[1]];
else dp[1] = max(cnt[a[0]] * a[0], cnt[a[1]] * a[1]);
for(int i = 2;i <= num;i ++){
if(a[i] != a[i-1] + 1) dp[i] = dp[i-1] + cnt[a[i]]*a[i];
else dp[i] = max(dp[i-1], a[i]*cnt[a[i]] + dp[i-2]);
}
cout << dp[num] << endl;
}
												

codeforces 260 div2 C题的更多相关文章

  1. codeforces 260 div2 B题

    打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被 ...

  2. codeforces #262 DIV2 B题 Little Dima and Equation

    题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...

  3. codedorces 260 div2 A题

    水题,扫描一遍看是否出现价格低质量高的情况. #include<cstdio> #include<string> #include<vector> #include ...

  4. codeforces 260 div2 A,B,C

    A:水的问题.排序结构.看看是否相同两个数组序列. B:他们写出来1,2,3,4,的n钍对5余.你会发现和5环节. 假设%4 = 0,输出4,否则输出0. 写一个大数取余就过了. B. Fedya a ...

  5. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  6. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  7. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  8. [codeforces 260]B. Ancient Prophesy

    [codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...

  9. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

随机推荐

  1. 关于ios 8 7 下的模态窗口大小的控制 代碼+場景(mainstoryboard)( Resizing UIModalPresentationFormSheet )

    1 代碼 UIViewController* modalController = [[UIViewController alloc]init];modalController.modalTransit ...

  2. maven 命令备忘

    1. 打包时 不执行测试 mvn package -Dmaven.test.skip=true

  3. Hadoop格式化HDFS报错java.net.UnknownHostException: localhost.localdomain: localhost.localdomain

    异常描述: 在对HDFS格式化,执行hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示: [shirdrn@localhost bin]$ hadoop n ...

  4. Project Euler 87 :Prime power triples 素数幂三元组

    Prime power triples The smallest number expressible as the sum of a prime square, prime cube, and pr ...

  5. 欧拉工程第65题:Convergents of e

    题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...

  6. Python中Lambda, filter, reduce and map 的区别

    Lambda, filter, reduce and map Lambda Operator Some like it, others hate it and many are afraid of t ...

  7. Xamarin.Android 入门之:xamarin使用webserver和html交互

    一.引言 如今,Android+html5开发已经成为最流行的开发模式. Android 中可以通过webview来实现和js的交互,在程序中调用js代码,只需要将webview控件的支持js的属性设 ...

  8. 2014-9-17二班----8 web project

    http://localhost:8080/rwkj1/indexServlet   地址请求后,,,,浏览器 地址栏没有变化 package cn.rwkj.servlet; import java ...

  9. 90. Subsets II

    题目: Given a collection of integers that might contain duplicates, nums, return all possible subsets. ...

  10. word文档标题级别批量更改——批量降级与升级实例

    word文档标题级别批量更改——批量降级与升级实例   word文档标题级别批量更改——批量降级实例 2012年12月21日16:30:44 现有一个3级文档结构的word文档,如下图所示 先需要将上 ...