首页 > 其他分享 >Codeforces Round #715 (Div. 2) C

Codeforces Round #715 (Div. 2) C

时间:2022-10-26 15:00:29浏览次数:52  
标签:const 数字 int 715 back Codeforces push Div

C. The Sports Festival

观察发现 我们显然选择一个数字开始后 我们拿周围的数字显然存在最优解(sort过)
这样就很金典了 n=2000 我们显然可以暴力区间dp
然后将转移只用从拿左边数字 和 右边数字O(1)转移即可

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int dp[2010][2010];
void solve() {
    int n;cin>>n;
    map<int,int>mp;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    vector<int>b,c;b.push_back(0),c.push_back(0);
    for(auto [x,y]:mp){
        b.push_back(x),c.push_back(y);
    }
    int m=b.size()-1;
    for(int i=0;i<=m;i++)for(int j=0;j<=m;j++)dp[i][j]=INF;
    for(int i=1;i<=m;i++)dp[i][i]=0;
    for(int len=2;len<=m;len++){
        for(int i=1,j=i+len-1;j<=m;j++,i++){
            dp[i][j]=min(dp[i][j],dp[i][j-1]+(b[j]-b[i])*c[j]);
            dp[i][j]=min(dp[i][j],dp[i+1][j]+(b[j]-b[i])*c[i]);
        }
    }
    cout<<dp[1][m]<<endl;
}
signed main(){
    fast
    int t;t=1;//cin>>t;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:const,数字,int,715,back,Codeforces,push,Div
From: https://www.cnblogs.com/ycllz/p/16828385.html

相关文章

  • Codeforces Round #697 (Div. 3) D
    D.CleaningthePhone金典贪心吧先sort从大到小考虑12两种情况显然要是我们当前now+最大的一个1那我们就直接break了继续我们知道了我们现在+最大的一个1不够我们......
  • 固定div尺寸 图片适应不变形处理样式
    .div-image{   width:200px;   height:132px;   overflow:hidden;   display:flex;   align-items:center;   justify-......
  • Solution: CF Round #830 (Div. 2) D1&D2 Balance
    FirstCFroundatCambridge.SolvedA,B,D1intheround.Droppedfrompurpletoblue...Stillalongwaytogo...Solution:CFRound#830(Div.2)D1&D2Balanc......
  • Codeforces Round #735 (Div. 2) C
    C.Mikasa显然我们应该用log或者O(1)的时间来回答一个ans当n>m时显然我们不能n^m==0所以直接cout0(1)我们知道的是n^i=?那么显然n^?=i(2)然后对于每一个n^i的值是不同的......
  • Codeforces Round #729 (Div. 2) B. Plus and Multiply (数论/暴力)
    https://codeforces.com/contest/1542/problem/B题目大意:有一个无限集合生成如下:1在这个集合中。如果x在这个集合中,x⋅a和x+b都在这个集合中。给定nab,问我们n......
  • Codeforces Round #743 A
    A.Book拓扑序我们一眼就能看出来主要是如何求读书的遍数我最开始想的就是把拓扑序处理出来类似于要几遍上升序列能把他全部覆盖显然求一遍不上升子序列即可但是我......
  • Codeforces 1672 F1. Array Shuffling
    题意给一个n个数的数列a,a[i]<=n定义一个操作:每次可以交换任意位置的两个值;定义最优操作:对于任意一个原数列的一组排列,使其通过尽可能少的操作变回原数列;求构造一组原......
  • Codeforces Round #802 (Div. 2)C. Helping the Nature(差分)
    题目链接题目大意:给你一个有n个元素的数组a,你可以通过一下三种操作使数组的每一个值都为0:选择一个下标i,然后让a[1],a[2]....a[i]都减一;选择一个下标i,然后让a[i......
  • Codeforces Round #829 (Div. 2) A-E
    比赛链接A题解知识点:枚举。只要一个Q后面有一个A对应即可,从后往前遍历,记录A的数量,遇到Q则数量减一,如果某次Q计数为0则NO。时间复杂度\(O(n)\)空间复杂度\(O(1)\)......
  • Codeforces Round #830 (Div. 2) C1
    C1.Sheikh(Easyversion)显然对于添加一个数进入区间是只增不减的这就提醒了我们此题具有单调性我们最后的答案肯定就是这一整个区间我们考虑怎么找到最小的答案相......