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

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

动态规划问题。

先做一个哈希,统计一下每个点数的个数p[i]。

dp[i]表示到i为止得到的最大点数

递推关系:

1.选择 i :选 i 就不能选择 i -1 , dp[i] = dp[i-2] + p[i] * i;

2.不选择 i : dp[i] = dp[i-1];

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100005;
ll p[maxn],dp[maxn];
int main(){
    ll i , n , x , maxn = -1;
    memset(p,0,sizeof(p));
    memset(dp,0,sizeof(dp));
    scanf("%I64d", &n);
    for(i = 1 ; i <= n ; i++){
        scanf("%I64d", &x);
        if(x > maxn)
            maxn = x ;
        p[x]++ ;
    }
    dp[1] = p[1] ;
    for(i = 2 ; i <= maxn ; i++)
        dp[i] = max( dp[i-1],dp[i-2]+p[i]*i );
    printf("%I64d\n", dp[maxn]);
    return 0;
}


过河卒(dp算法) 过河卒   内容: 题目描述 如图,A 点有一个过河卒,需要走到目标 B 点。卒行走规则:可以向下、或者向右。同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点。例如上图 C 点上的马可以控制 9 个点(图中的P1,P2...P8 和 C)。卒不能通过对方马的控制点。 棋盘用坐标表示,A 点(0,0)、B 点(n,m)(n,m 为 阅读详情

相关推荐

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

统计每个数字出现的次数,然后dpdp[i][0]表示选择

ZT在努力 471

Codeforces Round #260 (Div. 2) C Boredom

比赛当中,

724

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

C. 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 bore

Alex 1477

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

C. 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 bore

滴水穿石,慢慢积累,总会有成果 439

Codeforces Round #260 (Div. 2) C. Boredom【DP】

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

某科学的程序员 653

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

dp解Codeforces Round #260 (Div. 2)C. Boredom,欢迎讨论

Last Order 1900

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

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

随风的专栏 1077

Codeforces Round #260 (Div. 2) C

C. Boredom 题意:

A Cube Master 715

Codeforces Round #260 (Div. 2) 题解

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 pric

u010084308的专栏 1255

【索引】Codeforces Round #260 (Div. 1)

Problem A: Boredom(455A)

不慌不忙、不急不躁 1333

Codeforces Round #260 (Div. 2)

A. Laptopshttp://codeforces.com/contest/456/problem/A 1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 const int M=100010; 5 struct G{ 6 int x,y;...

102

Codeforces Round #260 (Div. 2) A ~ C

A. Laptops 传送门 A. Laptops 题意 其实我现在还搞不懂题意。Alex说质量和价格成反比,我还以为全部电脑都要满足才是Happy Alex,到比赛结束都没做出来。 早上看了一下其他人的原来有一个电脑满足就行?(求解释) 代码 #include using namespace std; #define LL long long #pragm

一只冰熊 2074

Codeforces Round #260 (Div. 2)455A - Boredom (DP)

C. 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 g

风尘_浪子 855

砝码称重(dp)

砝码称重 内容: 砝码称重(30分) 设有1g、2g、3g、5g、10g、20g的砝码各若干枚(其总重 要求: 输入方式:a1 a2 a3 a4 a5 a6 (表示1g砝码有a1个,2g砝码有a2个,…,20g砝码有a6个) 输出方式:Total=N (N表示用这些砝码能称出的不同重量的个数,但不包括一个砝码也不用的情况) 如输入:1_1_0_0_0_0 (注:下划线表示空格) 输出:TOTA

Roly 3326

九度OJ题目1554:区间问题

/* 判断如果k比连续子数组和的最大值还大,比最小值还小,那么肯定无解了,直接输出No */ #include #include using namespace std; const int maxn = 10005; int a[maxn]; int b[maxn]; int main(){ int n; while(~scanf("%d",&n)){

Roly 1440
上一篇: Codeforces Round #260 (Div. 2)B. Fedya and Maths
下一篇: Light OJ 1138 - Trailing Zeroes (III)
Roly_Yu
博客等级 码龄15年 29粉丝 226原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值