E - Addition on Segments

思路:

dp

dp[i]表示构成i的区间的右端点

先将询问按r排序

然后,对于每次询问,每次枚举 i 从 n-x 到 1,如果dp[i] >= l , 那么 dp[i+x] = max(dp[i+x], dp[j])

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e4 + ;
struct node {
int l, r, x;
bool operator < (const node & t) const {
return r < t.r;
}
}Q[N];
int dp[N];
int main() {
int n, q, l, r, x;
scanf("%d%d", &n, &q);
for (int i = ; i <= q; i++) {
scanf("%d%d%d", &Q[i].l, &Q[i].r, &Q[i].x);
}
sort(Q+, Q++q);
for (int i = ; i <= q; i++) {
l = Q[i].l;
r = Q[i].r;
x = Q[i].x;
for (int j = n-x; j >= ; j--) {
if(dp[j] >= l) dp[j+x] = max(dp[j+x], dp[j]);
}
dp[x] = r;
}
int ans = ;
for (int i = ; i <= n; i++) ans += (dp[i]>);
printf("%d\n", ans);
for (int i = ; i <= n; i++) if(dp[i]) printf("%d ", i);
return ;
}

Codeforces 981 E - Addition on Segments的更多相关文章

  1. Codeforces 981 D.Bookshelves(数位DP)

    Codeforces 981 D.Bookshelves 题目大意: 给n个数,将这n个数分为k段,(n,k<=50)分别对每一段求和,再将每个求和的结果做与运算(&).求最终结果的最大 ...

  2. Codeforces 981 共同点路径覆盖树构造 BFS/DP书架&最大值

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  3. Codeforces Round #535 E2-Array and Segments (Hard version)

    Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...

  4. CodeForces - 981E Addition on Segments

    考虑每个点i在什么情况下会成为最大值. 当选的区间子集是 包含i的区间的一个子集的时候,i肯定会是最大值. 所以我们就可以用这种方法得到所有点的可能的最大值是多少... 也就是说,最后的局面可以仅由一 ...

  5. Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化

    D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...

  6. Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】

    任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...

  7. 【20.51%】【codeforces 610D】Vika and Segments

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. codeforces A. Strange Addition 解题报告

    题目链接:http://codeforces.com/problemset/problem/305/A 题目意思:给出一个序列,需要从中选择一些数,这些数需要满足:任意的两个数中每一位至少有一个数满足 ...

  9. Codeforces Round #337 Vika and Segments

    D. Vika and Segments time limit per test:  2 seconds     memory limit per test:  256 megabytes input ...

随机推荐

  1. Cookie&Session与自定义session

    cookie与session的区别? cookie是保存在浏览器端的键值对 session是保存在服务器端的键值对 session依赖于cookie 摘自: http://bubkoo.com/201 ...

  2. 08: MySQL慢查询

    1.1 寻找慢查询   定义:我们将超过指定时间的SQL语句查询称为“慢查询”. 1.在mysql日志中开启慢查询日志 1. 修改配置文件  在 my.ini 增加几行:  主要是慢查询的定义时间(超 ...

  3. 10: VMware中扩展根分区

    1.1 添加一块硬盘 1.先给VMware添加一块60G硬盘 2.必须重启虚拟机才能识别到新加磁盘 fdisk -l        # 查看刚刚添加的硬盘 3.查看当前磁盘使用情况 df -hl   ...

  4. NOIP模拟题 2017.11.6

    题目大意 给定一个大小为n的数组,从中选出一个子集使得这个子集中的数的和能被n整除. 假设开始我没有做出来,那么我就random_shuffle一下,然后计算前缀和,有一个能被n整除,就输出答案.于是 ...

  5. topcoder srm 692 div1 -23

    1.给定一个带权有向图.选出一些边满足使得任意两点可相互到达的前提下使得选出的边的权值的最大最小差值最小. 思路:二分答案,然后枚举权值的范围判断是否可行. #include <stdio.h& ...

  6. uniGUI试用笔记(一)

    通过向导创建一个uniGUI应用服务器,工程中有三个文件: TUniServerModule = class(TUniGUIServerModule) TUniMainModule = class(T ...

  7. Bootstrap3基础 input-group glyphicon 输入框组与glyphicon图标

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  8. Python3 tkinter基础 Entry state 不可写 可以选 可复制的输入框

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Video Frame Synthesis using Deep Voxel Flow 论文笔记

    Video Frame Synthesis using Deep Voxel Flow 论文笔记 arXiv 摘要:本文解决了模拟新的视频帧的问题,要么是现有视频帧之间的插值,要么是紧跟着他们的探索. ...

  10. Python实现机器学习算法:感知机

    ''' 数据集:Mnist 训练集数量:60000 测试集数量:10000 ------------------------------ 运行结果: 正确率:81.72%(二分类) ''' impor ...