Codeforces Round #485 (Div. 2) C. Three displays
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的更多相关文章
- Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...
- Codeforces Round #485 (Div. 2) D. Fair
Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces Round #485 (Div. 2) A. Infinity Gauntlet
Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...
- Codeforces Round #485 (Div. 2) C题求三元组(思维)
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 ...
- Codeforces Round #485 Div. 1 vp记
A:对每种商品多源bfs一下每个点到该商品的最近距离,对每个点sort一下取前s个即可. #include<iostream> #include<cstdio> #includ ...
- 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 ...
随机推荐
- 寻找遗失的tags
现象:查询数据库,存在tags:{} 的字段,但是api查询时,不存在tags字段 日志定位Sample的init方法中对resource_metadata的扁平处理: 3.对应方法分析 在ceilo ...
- python之集合及其方法---整理集
集合的定义: 由不同元素组成.一组无序排列的可hash值.集合中元素必须是不可变类型 集合的定义方式: 由大括号组成: 每个元素用逗号分隔: 元素书写不是key-value形式: 集合是由不同元素组成 ...
- PHP上传图片例子
PHP上传图片例子 源码下载 两个文件: tu.php upload.php tu.php 代码: <?php ini_set("display_errors", &q ...
- ssh连接远程主机执行脚本的环境变量问题
近日在使用ssh命令ssh user@remote ~/myscript.sh登陆到远程机器remote上执行脚本时,遇到一个奇怪的问题: ~/myscript.sh: line n: app: co ...
- 100-days: twenty-six
Title: The Guardian(英国卫报) view on the Notre Dame fire: we share France's terrible loss Notre Dame 巴黎 ...
- maven 实用的命令
查询某个pom的来源: com.taobao.langyan langyan-client 命令: mvn dependency:tree -Dverbose -Dincludes=com.aliba ...
- css去掉滚动条
.main-layout-side::-webkit-scrollbar { display: none; } 主要代码: ::-webkit-scrollbar {display: none;}
- 【转】RabbitMQ基础——和——持久化机制
这里原来有一句话,触犯啦天条,被阉割!!!! 首先不去讨论我的日志组件怎么样.因为有些日志需要走网络,有的又不需要走网路,也是有性能与业务场景的多般变化在其中,就把他抛开,我们只谈消息RabbitMQ ...
- linux 7 更改主机名
1.在/etc/default/grub 中的GRUB_CMDLINE_LINUX 加上两条参数 #vim /etc/default/grub GRUB_CMDLINE_LINUX="cr ...
- dskinlite(uieasy mfc界面库)使用记录3:绘制动态元素(按钮控件通过隐藏方式修改图片显示)
效果图: 分别是:正常,正常鼠标悬停,按下,按下鼠标悬停 XML代码: 75,76行定义了一个image,注意id和index属性 初始化代码: click代码: 147,148,153,154:通过 ...