Codeforces Round #486-F.Rain and Umbrellas题解
一、题目链接:http://codeforces.com/contest/988/problem/F
二、题面

三、思路
很明显而且比较能想到的$dp$。
四、代码实现
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
#define MAXN 2018
typedef pair<int, int> PII;
typedef long long LL;
int dest, n, m, p[MAXN], rain_len[MAXN];
PII rains[MAXN];
map<int, int> mp;
bool wet[MAXN];
LL b[MAXN], dp[MAXN][MAXN];
int main(){
// freopen("input.txt", "r", stdin);
int t1, t2;
scanf("%d%d%d", &dest, &n, &m);
;i <= n;++i){
scanf("%d%d", &t1, &t2);
rains[i] = make_pair(t1, t2);
fill(wet + t1, wet + t2, true);
}
sort(rains + , rains + n + );
;i <= m;++i){
scanf("%d%d", &t1, &t2);
if(mp.find(t1) != mp.end())mp[t1] = min(mp[t1], t2);
else mp[t1] = t2;
}
m = ;
for(auto e : mp){
t1 = e.fst, t2 = e.snd;
b[++m] = t2, p[m] = t1;
}
b[m + ] = , p[m + ] = dest;
;i <= m;++i){
];j > p[i];--j){
]){
rain_len[i] = j - p[i];
break;
}
}
}
;
;i < p[];++i)dry &= !wet[i];
if(!dry)return !printf("-1\n");
else{
memset(dp, 0x3f, sizeof(dp));
dp[][] = ;
;i <= m;++i){
;j <= i;++j){
dp[i + ][i + ] = min(dp[i + ][i + ], dp[i][j] + b[j] * rain_len[i]);
dp[i + ][j] = min(dp[i + ][j], dp[i][j] + b[j] * (p[i + ] - p[i]));
}
}
LL ans = *min_element(dp[m + ], dp[m + ] + MAXN + );
cout << ans << endl;
}
;
}
Codeforces Round #486-F.Rain and Umbrellas题解的更多相关文章
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
随机推荐
- Gym 101147J Whistle's New Car(dfs)
https://vjudge.net/problem/Gym-101147J 题意: 有n个城市,每个城市有一个权值,表示在这个城市的加油站可以加多少油. 现在要计算每个城市i,有多少个城市j可以到达 ...
- Intel Caffe 与原生Caffe
1. 首先安装好docker,拉取intel caffe image: $ docker pull bvlc/caffe:intel 试着运行: $ docker run -it bvlc/caff ...
- JavaScript Number() Vs new Number()
最近在优化一个页面时候.IDEA 提示我错误的使用了包装类.当时感觉很诧异. 随后.我上Stack Overflow上面查了一下,终于发现了问题所在. new Number('123') 与 Numb ...
- java 获取本机的IP地址
方法一:这种方式有一定的局限性,在Linux下的执行结果是:本机的IP = xxx/127.0.1.1 (其中xxx是你的计算机名) public void getLocalIPAddress() { ...
- ssh隧道(通过跳板机)连接mysql
案例: A服务器 B服务器 C服务器mysql 现在mysql服务器C只能通过内网访问,B服务器就能通过内网连接访问到mysql A服务器无法直接连接C服务器mysql,所以要通过跳板机(跳板 ...
- 3d世界是怎样呈现到屏幕上的
要把一个3d物体呈现在屏幕上,要经过一系列的步骤. 描述3d世界 把3d世界绘制在二维屏幕上 如何描述一个3D世界? 数学家早就给出了3D世界的模型,我们日常最熟悉的3维坐标系就是一个欧几里得空间(线 ...
- QT Creator快捷键不能用
我现在搞明白了,热键之所以不行,是因为我开了Fakevim原因.关了fakevim就能用热键了. 如果开了Fakevim,连基本的Ctrl+C,这样的复制快捷键都不能用. 快速添加方法实体(.cpp) ...
- IOS NSBundle 的理解和 mainBundle 类方法详解
常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,用来获取 file 的完全 ...
- 第10课 C++中的动态内存分配
C++中的动态内存分配 C语言是通过库函数来完成动态内存分配的,而C++是通过关键字从语言层面支持的. C语言中的malloc是基于字节来进行内存申请的,C++中是基于类型来进行的. delete加上 ...
- CIE-LUV是什么颜色特征
参考文献:维基百科 a simple-to-compute transformation of the 1931 CIE XYZ color space, but which attempted pe ...