cf每日一题

Codeforces Round #812 (Div. 2)

(🕊了好久呜呜呜~)

 

 题目大意:对一个序列可以进行一次操作:选择两个索引 l , r ,对 l , r 范围内的数都减一,然后称f(a)为将所有数删为0所需要的次数,问对于a的所有排列b,是否满足f(a)<=f(b).

思路:可以把原数组变成差分数组,然后对于l,r范围内的数-1,就是对应差分数组的a[l]-1,a[r+1]+1,就是变成了左边的数-1,右边的数+1,然后需要的次数就为max(大于0的数,小于0的数)。然后对于a的全排列,需要次数的最小可能为sort排序之后的结果(升序降序都可以)。然后对比一下最小的,如果当前序列的次数小于等于最小的话,那么就满足条件,否则就输出NO。

最后记得还要开longlong

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N],cnt[N];


int main()
{
	int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i =1;i<=n;i++){
        cin>>s[i];
        cnt[i]=s[i]-s[i-1];
        }
       ll l=0,r=0;
        for(int i =1;i<=n;i++)
        {
            if(cnt[i]>0)
            l+=cnt[i];
            else 
            r+=abs(cnt[i]);
        }
        ll res=max(l,r);
        sort(s+1,s+1+n);
        l=0,r=0;        
        for(int i =1;i<=n;i++)
        {
            cnt[i]=s[i]-s[i-1];      
            if(cnt[i]>0)
            l+=cnt[i];
            else 
            r+=abs(cnt[i]);                  
        }
        if(res<=l+r)
        cout<<"YES\n";
        else cout<<"NO\n";

    }
	return 0;
}

<think>我们为准备安徽省选的信息学竞赛选手设计一个动态规划(DP)提升计划题单。题单将覆盖DP的各个重要知识点,题目难度从基础到省选提高难度。题目来源于各大OJ平台(如洛谷、Codeforces等),并附上链接。 ### 动态规划提升计划题单(20题) #### 一、线性DP(4题) 1. **经典问题** [P1091 合唱队形](https://www.luogu.com.cn/problem/P1091) - 最长上升子序列变式 [P1280 尼克的任务](https://www.luogu.com.cn/problem/P1280) - 倒序线性DP 2. **区间DP** [P1880 石子合并](https://www.luogu.com.cn/problem/P1880) - 环形区间DP [CF607B Zuma](https://codeforces.com/problemset/problem/607/B) - 区间消除DP #### 二、背包问题(3题) 1. **变形与优化** [P1776 宝物筛选](https://www.luogu.com.cn/problem/P1776) - 多重背包单调队列优化 [P3188 梦幻岛宝珠](https://www.luogu.com.cn/problem/P3188) - 01背包按位分层 #### 三、树形DP(4题) 1. **基础与进阶** [P1352 没有上司的舞会](https://www.luogu.com.cn/problem/P1352) - 经典树形DP [P2607 骑士](https://www.luogu.com.cn/problem/P2607) - 基环树DP [CF767C Garland](https://codeforces.com/problemset/problem/767/C) - 树形DP+子树和 #### 四、状态压缩DP(3题) 1. **经典模型** [P1896 互不侵犯](https://www.luogu.com.cn/problem/P1896) - 状压DP [P2704 炮兵阵地](https://www.luogu.com.cn/problem/P2704) - 状压DP+滚动数组 [CF8C Looking for Order](https://codeforces.com/problemset/problem/8/C) - 状压DP+路径优化 #### 五、数位DP(3题) 1. **数字统计** [P2657 windy数](https://www.luogu.com.cn/problem/P2657) - 数位DP基础 [P2602 数字计数](https://www.luogu.com.cn/problem/P2602) - 统计数字出现次数 [CF55D Beautiful numbers](https://codeforces.com/problemset/problem/55/D) - 数位DP+状态压缩 #### 六、动态DP(3题) 1. **动态维护** [P4719 动态DP](https://www.luogu.com.cn/problem/P4719) - 树链剖分+矩阵转移 [CF750E New Year and Old Subsequence](https://codeforces.com/problemset/problem/750/E) - 线段树维护DP矩阵 --- ### 训练建议 1. **刷题顺序**:按分类逐个突破,先线性DP、背包,再树形DP、状压DP,最后数位DP和动态DP。 2. **时间分配**:每天2-3题,每道题完成后写详细题解,记录状态设计思路和转移方程。 3. **难点突破**:遇到难题时先思考1小时,再看题解,重点学习状态设计技巧。 §§相关问题§§ 1. 树形DP中如何处理基环树问题? 2. 动态DP为什么需要结合树链剖分? 3. 数位DP中如何优化状态空间? 4. 状态压缩DP如何解决高维状态的内存问题? 5. 如何判断一个DP问题是否可以使用斜率优化?</think>### 动态规划(DP)专项提升题单(安徽省选备战) #### 一、基础DP类型(10题) 1. **线性DP** [P1091 合唱队形](https://www.luogu.com.cn/problem/P1091) - 双向LIS [P1280 尼克的任务](https://www.luogu.com.cn/problem/P1280) - 时间轴DP [CF846C Four Segments](https://codeforces.com/problemset/problem/846/C) - 前缀和+枚举 2. **背包问题** [P1776 宝物筛选](https://www.luogu.com.cn/problem/P1776) - 多重背包单调队列 [P3188 梦幻岛宝珠](https://www.luogu.com.cn/problem/P3188) - 按位分层背包 [CF837D Round Subset](https://codeforces.com/problemset/problem/837/D) - 二维背包 3. **区间DP** [P4342 Polygon](https://www.luogu.com.cn/problem/P4342) - 环形区间处理 [CF149D Coloring Brackets](https://codeforces.com/problemset/problem/149/D) - 括号匹配DP --- #### 二、树形DP(8题) 1. **基础树形DP** [P1352 没有上司的舞会](https://www.luogu.com.cn/problem/P1352) [P2015 二叉苹果树](https://www.luogu.com.cn/problem/P2015) 2. **换根DP** [P3478 STA-Station](https://www.luogu.com.cn/problem/P3478) [CF1092F Tree with Maximum Cost](https://codeforces.com/problemset/problem/1092/F) 3. **基环树DP** [P2607 骑士](https://www.luogu.com.cn/problem/P2607) [CF835F Roads in the Kingdom](https://codeforces.com/problemset/problem/835/F) --- #### 三、状态压缩DP(8题) 1. **棋盘模型** [P1896 互不侵犯](https://www.luogu.com.cn/problem/P1896) [P2704 炮兵阵地](https://www.luogu.com.cn/problem/P2704) 2. **路径问题** [P1171 售货员的难题](https://www.luogu.com.cn/problem/P1171) [CF11D A Simple Task](https://codeforces.com/problemset/problem/11/D) - 简单环计数 3. **集合划分** [P5999 Kangaroo](https://www.luogu.com.cn/problem/P5999) [CF1316E Team Building](https://codeforces.com/problemset/problem/1316/E) --- #### 四、数位DP(6题) 1. **经典问题** [P2657 windy数](https://www.luogu.com.cn/problem/P2657) [P2602 数字计数](https://www.luogu.com.cn/problem/P2602) 2. **进阶问题** [CF55D Beautiful numbers](https://codeforces.com/problemset/problem/55/D) [P4127 同类分布](https://www.luogu.com.cn/problem/P4127) --- #### 五、动态DP(6题) 1. **矩阵加速** [P4719 动态DP](https://www.luogu.com.cn/problem/P4719) [CF750E New Year and Old Subsequence](https://codeforces.com/problemset/problem/750/E) 2. **线段树维护** [P4751 动态DP](https://www.luogu.com.cn/problem/P4751) [CF1380F Strange Addition](https://codeforces.com/problemset/problem/1380/F) --- #### 六、期望DP(6题) 1. **经典模型** [P1850 换教室](https://www.luogu.com.cn/problem/P1850) [CF518D Ilya and Escalator](https://codeforces.com/problemset/problem/518/D) 2. **图论期望** [P3758 可乐](https://www.luogu.com.cn/problem/P3758) [CF235B Let's Play Osu!](https://codeforces.com/problemset/problem/235/B) --- #### 七、优化技巧(6题) 1. **斜率优化** [P3195 玩具装箱](https://www.luogu.com.cn/problem/P3195) [CF674C Levels](https://codeforces.com/problemset/problem/674/C) 2. **决策单调性** [P1912 诗人小G](https://www.luogu.com.cn/problem/P1912) [CF868F Yet Another Minimization](https://codeforces.com/problemset/problem/868/F) --- ### 训练计划建议 1. **阶段安排**: ```mermaid gantt title DP专项月计划 section 基础阶段 线性/背包DP :a1, 2023-11-01, 7d 树形DP :a2, after a1, 7d section 进阶阶段 状压/数位DP :a3, after a2, 7d 动态DP :a4, after a3, 7d section 强化阶段 期望DP :a5, after a4, 5d 优化技巧 :a6, after a5, 5d ``` 2. **每日训练**: - 上午:2题新类型(按计划顺序) - 下午:1题昨日错题 + 1题综合题 - 晚上:模板默写 + OI Wiki复习 3. **重点突破**: - 树形DP换根法(必考) - 状态压缩的位运算技巧 - 矩阵加速的动态DP写法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值