Codeforces Round #485 (Div. 2) C. Three displays

题目连接:

http://codeforces.com/contest/987/problem/C

Description

It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.

There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.

The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.

Sample Input

5
2 4 5 4 10
40 30 20 10 40

Sample Output

90

题意

找到一个三元组,组内元素为(i, j, k) ,有\(i<j<k\),问最小花费的三元组的花费为多少

Find a tuple whose elements fit the relationship \(i<j<k\). Each element has its cost.Find the mininum cost.

题解:

dp[i][o] 代表装了第i个物品后,共装了o个物品时的最小花费,dp[i][o] = min (dp[i][o],dp[k][o-1]+cost[i]); 其中 \(w[k]<w[i]\)

dp[i][o] represent we put the i-th element into the bag, after that there are \(o\) elements in the bag. The transform eqution is dp[i][o] = min (dp[i][o],dp[k][o-1]+cost[i]); in case of \(w[k]<w[i]\).

代码

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
int n;
pair<int,long long> p[3010];
long long dp[3010][3];
const long long INF = 0x7ffffffffffll; int main() {
cin>>n;
for (int i=1;i<=n;i++) {
cin>>p[i].first;
}
for (int i=1;i<=n;i++) {
cin>>p[i].second;
}
for (int i=1;i<=n;i++) {
dp[i][1]=p[i].second;
dp[i][2]=dp[i][3]=INF;
for (int o=1;o<i;o++) {
if (p[o].first<p[i].first) {
dp[i][2] = min(dp[i][2],dp[o][1]+p[i].second);
dp[i][3] = min(dp[i][3],dp[o][2]+p[i].second);
}
}
}
long long ans = INF;
for (int i=3;i<=n;i++)
ans = min(ans,dp[i][3]);
cout << (ans==INF?-1:ans) << endl;
}

Codeforces Round #485 (Div. 2) C. Three displays的更多相关文章

  1. Codeforces Round #485 (Div. 2)

    Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #485 (Div. 2) D. Fair

    Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...

  3. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  4. Codeforces Round #485 (Div. 2) E. Petr and Permutations

    Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...

  5. Codeforces Round #485 (Div. 2) A. Infinity Gauntlet

    Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...

  6. Codeforces Round #485 (Div. 2) C题求三元组(思维)

    C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #485 (Div. 2)-B-High School: Become Human

    B. High School: Become Human time limit per test 1 second memory limit per test 256 megabytes input ...

  8. Codeforces Round #485 Div. 1 vp记

    A:对每种商品多源bfs一下每个点到该商品的最近距离,对每个点sort一下取前s个即可. #include<iostream> #include<cstdio> #includ ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. Tomcat的三种安装方式:解压版、安装版、配置成Windows服务版

    https://blog.csdn.net/Jessica_XLF/article/details/81711429

  2. 布署配置管理中心apollo

    Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性,适用于微服务配置管理场景. 服 ...

  3. 在Html页面中调用ajax代码

    以最原始的XMLHttpRequest形式,实现ajax. 封装的方法 1 /** 2 * 发送一个 AJAX 请求 3 * @param {String} method 请求方法 4 * @para ...

  4. 网站改版应对google

    客户要求修改网站,这会给我们带来问题!为了保留他的网站权重和关键字排名,我们必须在做网站修改工作之前分析他原来网站的连接结构和标题,这样我才能更好地保证他原来网站的整体权重不会有大的变化!以下是我们根 ...

  5. 认识socket

    socket socket也称套接字,网络编程的基础.一般情况下我不喜欢直接去说socket的函数都是怎么用的,那个很多人都写出来了,而且肯定比我好的有的是. 但是今天想写的是我的理解中,产生sock ...

  6. TreeView的三种状态,全选,全不选,半选中

    我知道的设置treeview节点的三种状态,如果不是买的控件,那么通过代码,只能设置两种状态,我知道的有三种方法, 第一种是重写treeview,第二种是把三种状态做成小图标,让节点复选框随着不同的状 ...

  7. 监听端口,获取webService请求报文

    第一步下载我们的wsdl文件到本地 第二步建立一个测试webservice工程,把wsdl放在项目里面 第三步把测试webservice中的wsdlLocation改成localhost.....你的 ...

  8. php 通过扫描二维码关注公众号

    class Wxfollow {     protected $appid = 'wxf1d959b99f33b156';     protected $secret = '248f3a5606045 ...

  9. Struts2源码解析2

    看了前面一节对Struts2各个模块运行有了大概了解,也对调用的函数有了一定的了解,本节希望打断点跑一个Struts2例子! 还是放在struts2结构图: 一:项目启动后解析web.xml文件,会解 ...

  10. 关于CDN与缓存(浏览器和CDN)

    本文目录:一.引入 二.CDN定义 三.关于缓存 四.浏览器缓存 一.引入 客户端直接从源站点获取数据,当服务器访问量大时会影响访问速度,进而影响用户体验,且无法保证客户端与源站点间的距离足够短,适合 ...