一、题目链接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题解的更多相关文章

  1. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  2. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  3. Codeforces Round #486 (Div. 3) E. Divisibility by 25

    Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. 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 ...

  5. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  6. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  7. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  8. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  9. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  10. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

随机推荐

  1. springboot2 统一返回结果

    统一返回结果是说,不用在controller层,new一个对象,或用工厂创建这个对象,再返回这个对象,而是这个Action该返回什么就返回什么, 我们再通过mvc的流程,再对返回对象做进一步的封装,以 ...

  2. linuxI/O重定向

    假设有这么一段python3程序: import sys ")sys.stderr.write("stderr1 ") 现在想要把程序的输出以及错误信息都存在文件中. 一 ...

  3. IOS-常用第三方开源框架介绍

    iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角) 时间:2015-05-06 16:43:34      阅读:533      评论:0      收藏:0      [点我收藏+] ...

  4. MarkdownPad2 下一些设置

    MarkdownPad2注册码: 邮箱: Soar360@live.com 授权秘钥: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6 ...

  5. Collections中的各种方法

    一.各种方法介绍 Counter 统计个数   elements  most_common  subtract defaultdict 字典默认值 ChainMap  合并多个映射对象(字典) Ord ...

  6. 002——数组(二)each() list() implode() explode() in_array()

    <?php /** * 数组(二)each() list() implode() explode() in_array() */ /*implode() 把数组拆分成字符串 * explode( ...

  7. 从客户端中检测到有潜在危险的 Request.Form 值 方法

    由于在.net中,Request时出现有HTML或Javascript等字符串时,系统会认为是危险性值.立马报出“从客户端 中检测到有潜在危险的Request.Form值”这样的错. 解决方案一:   ...

  8. 几句话概括理查德成熟度模型(RESTful)

    近期做的项目中准备引入RESTful风格,特地进行了一些学习,其中比较重点的有一个理查德成熟度模型(Richardson Maturity Model),模型提出了四个等级(0-3),如下图 其中只有 ...

  9. IP地址分配机构

    IP地址分配机构 全球ip地址分配机构 互联网编号分配机构(IANA,Internet Assigned Numbers Authority)负责分配和规划IP地址,以及对TCP/UDP公共服务的端口 ...

  10. 安装wamp后,127.0.0.1可以访问,localhost不能访问

    今天安装wamp后,127.0.0.1可以访问,localhost不能访问,出现 “error You don't have permission to access”的错误, 网上查了下,很多方法都 ...