eduCF#61 C. Painting the Fence /// DP 选取k段能覆盖的格数
题目大意:
给定n m
接下来给定m个在n范围内的段的左右端 l r
求选取m-2段 最多能覆盖多少格
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define mem(i,j) memset(i,j,sizeof(i))
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int N=5e3+; int n, m, L[N], dp[N];
// L[i] 表示 所有画到i的段中 l最左的一段的左端
// dp[i] 表示到i为止 选出当前k段 的最优解 int main()
{
while(~scanf("%d%d",&n,&m)) {
inc(i,,n) L[i]=i+, dp[i]=;
// L[]置为i+1是为了表示没有被画过的状态
inc(i,,m) {
int l,r; scanf("%d%d",&l,&r);
inc(j,l,r) L[j]=min(L[j],l);
}
inc(k,,m-) {
dec(i,n,) dp[i]=max(dp[L[i]-]+i-L[i]+,dp[i]);
// L[i]~i的一段都被画了 长度为 i-L[i]+1
// 所以 dp[L[i]-1] 加上 L[i]到i被画的一段 更新dp[i]
inc(i,,n) dp[i]=max(dp[i],dp[i-]);
// 短的段存在更优的方案 自然可以更新长的段
}
printf("%d\n",dp[n]);
} return ;
}
eduCF#61 C. Painting the Fence /// DP 选取k段能覆盖的格数的更多相关文章
- Educational Codeforces Round 61 Editorial--C. Painting the Fence
https://codeforces.com/contest/1132/problem/C 采用逆向思维,要求最大的覆盖,就先求出总的覆盖,然后减去删除两个人贡献最少的人 #include<io ...
- eduCF#61 F. Clear the String /// 区间DP 消除连续一段相同字符 全部消完的最少次数
题目大意: 给定字符串 每次消除可消除连续的一段相同的字符的子串 求消除整个字符串的最少消除次数 #include <bits/stdc++.h> using namespace std; ...
- SGU 183. Painting the balls( dp )
dp..dp(i, j)表示画两个点为i-j, i的最优答案. dp(i, j) = min{ dp(i-j, k) } + cost[i] (1≤k≤M-j) 令f(i, j) = min{dp(i ...
- [luogu P2205] [USACO13JAN]画栅栏Painting the Fence
[luogu P2205] [USACO13JAN]画栅栏Painting the Fence 题目描述 Farmer John has devised a brilliant method to p ...
- 洛谷 画栅栏Painting the Fence 解题报告
P2205 画栅栏Painting the Fence 题目描述 \(Farmer\) \(John\) 想出了一个给牛棚旁的长围墙涂色的好方法.(为了简单起见,我们把围墙看做一维的数轴,每一个单位长 ...
- Painting The Fence(贪心+优先队列)
Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...
- 洛谷——P2205 [USACO13JAN]画栅栏Painting the Fence
题目描述 Farmer John has devised a brilliant method to paint the long fence next to his barn (think of t ...
- CodeForce - 1187 E. Tree Painting (换根dp)
You are given a tree (an undirected connected acyclic graph) consisting of nn vertices. You are play ...
- poj1821 Fence(dp,单调队列优化)
题意: 由k(1 <= K <= 100)个工人组成的团队应油漆围墙,其中包含N(1 <= N <= 16 000)个从左到右从1到N编号的木板.每个工人i(1 <= i ...
随机推荐
- 数据结构与算法简记--redis有序集合实现-跳跃表
跳表 定义 为一个值有序的链表建立多级索引,比如每2个节点提取一个节点到上一级,我们把抽出来的那一级叫做索引或索引层.如下图所示,其中down表示down指针,指向下一级节点.以此类推,对于节点数为n ...
- eslint 禁用命令
/* eslint-disable */ ESLint 在校验的时候就会跳过后面的代码 还可以在注释后加入详细规则,这样就能避开指定的校验规则了 /* eslint-disable no-new */ ...
- LLppdd's class meeting!
LLppdd's class meeting! Time Limit: 1 s Memory Limit: 256 MB 题目背景 LLppdd 有一个可爱团结的班级,他们会定期举行班会活动...比如 ...
- axure破解版
axure 破解版 https://www.cnblogs.com/lianghong/p/9385233.html 授权: zdfans.com 注册码: gP5uuK2gH+iIVO3Y ...
- fragment中的onCreateView和onViewCreated的区别和
(1) onViewCreated在onCreateView执行完后立即执行. (2) onCreateView返回的就是fragment要显示的view.
- strings - 显示文件中的可打印字符
总览 (SYNOPSIS) strings [-a|-|--all] [-f|--print-file-name] [-o] [--help] [-v|--version] [-n min-len|- ...
- express 路由能力
demo var express=require("express"); var app=express(); app.get("/",function(req ...
- 6、Python 中 利用 openpyxl 读 写 excel 操作
__author__ = 'Administrator' from openpyxl import load_workbook # Excel_Util 类 class Excel_util: #初始 ...
- k8s-1.16 二进制安装
环境机器配置: 172.16.153.70 master 172.16.77.121 node1 172.16.77.122 node2 系统初始化 [root@iZbp1c31t0jo4w553hd ...
- Java IO之处理流
一.处理流: 增强功能,提供性能,在节点流之上. 二.节点流与处理流的关系 节点流(字节流.字符流)处于IO操作的第一线,所有操作必须通过它们进行: 处理流可以对其他流进行处理(提高效率或操作灵活性) ...