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. Keil uVision4 创建51单片机工程

    Keil uVision4 创建51单片机工程 版权声明:未经授权,严禁转载! 在学习51单片机的过程当中,我们需要使用 Keil uVision4 来创建一个项目,今天就来图示一下创建的流程. 首先 ...

  2. ldap集成zabbix

    zabbix版本:3.0.7 ldap认证配置: zabbix管理员登录-->管理-->认证,选择ldap方式 参照以上格式填写,需注意配置完成后需在zabbix上创建与ldap同名账户才 ...

  3. 2018-2019-1 20189206 《Linux内核原理与分析》第七周作业

    linux内核分析学习笔记 --第六章 进程的描述和进程的创建 学习重点--子进程的创建以及运行流程 进程描述和进程的创建 操作系统的三大功能--进程管理.内存管理和文件系统. 在linux内核中利用 ...

  4. Microsoft Visual Studio 2010(vs10)安装与使用

    安装1.下载软件: 云盘分享http://pan.baidu.com/s/1i4JL9GT 2.安装 打开Microsoft Visual Studio 2010目录,双击setup.exe ,运行 ...

  5. route 工具

    route工具 route工具主要用来查看或修改内核路由表 查看内核路由表 route [-nee] 参数说明: -n:不要使用协议或主机名称,直接使用 IP 或 port number:-ee:使用 ...

  6. gerrit的使用笔记

    1.clone的时候一定要同时选择上clone with commit-msg hook和ssh,这样才能使用change id,同时使用ssh push到remote. 2.如果是使用了clone ...

  7. 给ThinkPad E470C 换个高分屏(1080P)

  8. P4782 【模板】2-SAT 问题

    https://www.luogu.org/problemnew/show/P4782 链接 https://www.luogu.org/problemnew/show/P4782 思路 选a就必须选 ...

  9. 题解—— 洛谷 p1993 小K的农场(差分约束&负环判断)

    看到题就可以想到差分约束 判断负环要用dfs,bfs-spfa会TLE 4个点 bfs-spfa #include <cstdio> #include <algorithm> ...

  10. 深度学习课程笔记(十四)深度强化学习 --- Proximal Policy Optimization (PPO)

    深度学习课程笔记(十四)深度强化学习 ---  Proximal Policy Optimization (PPO) 2018-07-17 16:54:51  Reference: https://b ...