首页 > 其他分享 >CF455A补题

CF455A补题

时间:2024-01-11 13:01:03浏览次数:19  
标签:const int CF455A i64 补题 dp mp

思路

取与不取的问题,用dp就行

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
const i64 inf = 8e18;
typedef pair<int, int> pii;
const int N = 1e5 + 10;

i64 dp[N];

void solve() {
    int n;
    cin >> n;
    map<int, int> mp;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mp[x] ++;
    }
    dp[1] = mp[1];
    for (int i = 2; i <= 100000; i++) {
        dp[i] = max(dp[i - 1], dp[i - 2] + 1ll * i * mp[i]);
    }

    cout << dp[100000];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t --) solve();

    return 0;
}

标签:const,int,CF455A,i64,补题,dp,mp
From: https://www.cnblogs.com/kichuan/p/17958341

相关文章

  • CF1374D(补题)
    思路用map记录有多少个相同的(a[i]%k)的值,然后利用等差数列求和公式求最大值就行。比如a=[6,7,5,9,50,31],且k=3。a[i]%k-->a=[0,1,2,0,2,1]。x要分别为25才能使得a[2]和a[6]满足题目要求ac代码#include<bits/stdc++.h>usingnamespacestd;using......
  • atcoder补题计划
    DPABC275EABC274DABC274EABC271EABC270DABC266D状态机模型ABC265Emap存状态+步骤型遍历(注意DP顺序)+复杂度证明ABC262D关于数字的DP,将一类数字分成一个状态加粗样式ABC261D没啥好说的看题目写DPABC253E关于数字的DPABC251E状态机DPABC197E在一维轴上行走的DP......
  • 补题--I题
    I.Letters算法:前缀和+二分(lower_bound)不开ll见祖宗#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;llt,n,m;constintN=2e5+10;#defineeps(a,b)for(inti=a;i<=b;i++)llb[N],s[N];intmain(){ios::sync_with_stdio(false);cin.tie()......
  • 补题日志
    补题日志**Codeforcesrating:1770**goal:1900ATcoderrating:1254goal:1600CodeforcesRound915(Div.2)D不难发现,设当前排列为\(q_1,q_2\dotsq_n\),把\(q_1\)移到末尾,造成的影响有:对于前缀中\(\text{mex}_i<q_1\)的\(i\),移动后不改变它的值。对于前......
  • Acwing秋季每日一题补题---搜索字符串
    搜索字符串题目链接思路:字符串哈希+滑动窗口当然因为符合题意的子串会重复,所以我们要考虑去重的问题代码:#include<bits/stdc++.h>usingnamespacestd;#defineintunsignedlonglongconstintN=2e5+10;constintP=131;chara[N],b[N];//字符串intcnt[26];//统......
  • 2023.12.9补题
    一.关于优先队列的题目atcoder周赛题目   总结:本题利用用优先队列自动排序,首先我们需要明确的是先去更新小的,小的如果有更新不了的那么一定不会有人再和他融合了这样我们选择开一个大根堆greater,从小到大排列,然后我们开一个pair记录数值和出现次数,然后每次操作先判断他周......
  • 集训队胡策2023-2024补题记录
    CTT结束后发现自己胡策题都没咋补,这下尴尬了。主要原本胡策就打着玩的(怎么CTT平均难度比胡策还要简单啊.jpg。还是随便写几篇题解吧。先来个补全进度表,根据胡策OJ或qoj通过情况来评判:测试赛(10.22)A+BProblem奥林匹克五子棋元旦激光炮Day1(10.23)优惠购......
  • 补题记录
    https://codeforces.com/contest/1903/problem/E交互题GeoGamehttps://codeforces.com/contest/1903/problem/F2-sat图论题Babysittinghttps://codeforces.com/contest/1903/problem/D2一个奇怪的题目https://atcoder.jp/contests/abc331/tasks/abc331_f线段......
  • Codeforces Round 912 (Div. 2)补题B、C、D1
    CodeforcesRound912(Div.2)B.StORageroom思路\(a_i\)=\(M_i\)\(_1\)&\(M_i\)\(_2\)&\(M_i\)\(_3\)&...&\(M_i\)\(_n\)\((i!=j)\)ac代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong......
  • 字典树补题记录
    Luogu-P6587超超的序列加强AC2023.11.19发现\(x\le20\),可以取编号01串的后\(x\)位,按字典树的形式,线段树的思想。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;#definedebug(x)cout<<#x<<"="<<x<<endl;constint......