Codeforces 1101F Trucks and Cities dp (看题解)
一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导。。。
感觉有这个误导之后很难往dp那个方向靠。。
dp[ k ][ i ][ j ]表示把 i, j 这个区间分成 k 段, 所有段的最大值的最小值为多少。 然后dp的过程中把车代进去求答案。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m;
int a[N], f[][N][N];
vector<pair<PII, int>> vc[N]; int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i <= m; i++) {
int s, f, c, r;
scanf("%d%d%d%d", &s, &f, &c, &r);
r = min(f - s + , r + );
vc[r].push_back(mk(mk(s, f), c));
}
LL ans = ;
int cur = , lst = ;
for(int i = ; i <= n; i++)
for(int j = i; j <= n; j++)
f[cur][i][j] = a[j] - a[i];
for(int k = ; k <= ; k++) {
swap(cur, lst);
for(auto& t : vc[k - ]) {
ans = max(ans, 1ll * f[lst][t.fi.fi][t.fi.se] * t.se);
}
for(int i = ; i <= n; i++) {
int p = i + k - ;
for(int j = i + k - ; j <= n; j++) {
while(p < j && f[lst][i][p] <= a[j] - a[p]) p++;
f[cur][i][j] = min(f[lst][i][p], a[j] - a[p - ]);
}
}
}
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces 1101F Trucks and Cities dp (看题解)的更多相关文章
- codeforces 1101F Trucks and Cities 区间dp+单调优化 好题
题目传送门 题意简述:(来自洛谷) 有n个城市坐落在一条数轴上,第ii个城市位于位置ai. 城市之间有m辆卡车穿行.每辆卡车有四个参数:si为起点编号,fi为终点编号,ci表示每行驶1个单位长 ...
- Codeforces 442D Adam and Tree dp (看题解)
Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. ...
- Codeforces 596D Wilbur and Trees dp (看题解)
一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)
第一次看到这种骚东西, 期望还能二分的啊??? 因为存在重置的操作, 所以我们再dp的过程中有环存在. 为了消除环的影响, 我们二分dp[ 0 ][ 0 ]的值, 与通过dp得出的dp[ 0 ][ 0 ...
- Codeforces 513E2 Subarray Cuts dp (看题解)
我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中 ...
- Codeforces 983C Elevator dp (看题解)
Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...
- Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...
- Codeforces 498B Name That Tune 概率dp (看题解)
Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...
随机推荐
- $Django redis内存数据库 (知识回顾cmd切换目录)
知识小回顾 #切换盘 C:\Users\WangDong>f: F:\> #切换文件 F:\>cd redis F:\redis> #返回上一级 F:\DJ\dj8>cd ...
- OpenCV中RGB和HSV转换的问题
1.一般情况下HSV模型各分量的取值范围为:H为0到360°,S为0到100%,V为0到255.但是在OpenCV中在由RGB转换到HSV的过程中,发现HSV中H为0到180°,S为0到255,V为0 ...
- 1-HTML Attributes
下表列举了常用的Html属性 Attribute Description alt Specifies an alternative text for an image, when the image ...
- javacv:调取本地摄像头,抓取人脸,保存为图片
MAVEN: <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv-platf ...
- signal & slot
The Qt signals/slots and property system are based on the ability to introspect the objects at runti ...
- 欲善其工必先利其器-----ThinkPad E430加装SSD固态硬盘和内存
大概13年5月左右入手的小黑ThinkPad E430 当时辞职换工作换城市所以预算有限,4k左右大洋买下了这款笔记本电脑.3年左右的时间,一直使用单位电脑,偶尔使用小黑真心崩溃.你会发现你会有放弃使 ...
- sublime text3 golang插件(golang build)
1 前言 先前条件: sublime text3:下载地址:http://www.sublimetext.com/3 golang:下载地址:https://golang.google.cn/dl/ ...
- 协程,twisted
最原始的请求url_list=[ 'https://www.cnblogs.com/yunxintryyoubest/category/1338759.html', 'https://www.cnbl ...
- 一个简单的Loading控件
实现效果如下: 使用方法: 在layout文件中添加以下代码: <com.example.jack.ui.widget.RingLoading android:layout_width=&quo ...
- 13)django-ORM(连表一对多,外键创建,创建数据,3种查询)
一对多需要使用外键 一:外键创建ForeignKey b=models.ForeignKey(to="Business",to_field=("id"))#dj ...