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 ...
随机推荐
- window.frames && iframe 跨页面通信
1.定义 frames[]是窗口中所有命名的框架组成的数组.这个数组的每个元素都是一个Window对象,对应于窗口中的一个框架. 2.用法 假设iframe 是一个以存在的 iframe 的 ID 和 ...
- angular-cli 文档
Angular/angular-cli 原文来自:https://github.com/angular/angular-cli Angular/angular-cli 原文来自:https://git ...
- 动态规划-House Robber
2018-04-29 20:20:56 House Robber问题是leetcode上经典的系列题,这里对其中的题目做一个讲解. 198. House Robber 问题描述: 问题求解: 本质上就 ...
- Confluence 6 使用一个页面为站点的默认页面
如果你希望有更多的控制,你可以选择一个 Confluence 的原始页面为你的站点载入页面来替换掉将用户发到主面板中.请查 Configuring the Site Home Page 页面来查看更多 ...
- 解决mysql安装报错:无法启动此程序,因为计算机丢失MSVCP120.dll
问题一: 因为装的是新系统,所以遇到mysql启动报错:无法启动此程序,因为计算机丢失MSVCP120.dll 后来参考这篇文章https://blog.csdn.net/huacode/articl ...
- 创建对象并生成结果的3个步骤-Chapter 3 P38
必须完成3个步骤才能创建对象并生成结果: 1 创建对象 namespace LanguageFeatures { public class Product { public int Product ...
- 使用Bus.js进行兄弟(非父子)组件通信
首先需要在任意地方添加一个bus.js: 在bus.js里面 写入下面信息 import Vue from 'vue' export default new Vue; 在需要通信的组件都引入Bus.j ...
- HDU1102 最小生成树prim算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 题意:给出任意两个城市之间建一条路的时间,给出哪些城市之间已经建好,问最少还要多少时间使所有的城 ...
- vue2 过渡动画
<body> <div id="app"> <transition name="move"> // transition里面 ...
- JDK1.7+eclipse 4.4(luna)+pydev4.4.5构建django开发环境
最近一直用pycharm搞django学习,但是到2017年随着版本的不断更新,启动之慢,吃资源吃内存越来越严重.果然想找一个IDE替代品. 之前用java开发分布式WEB应用,用eclipse开了N ...