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;
}

最新文章

  1. easyui datagrid 点击表头的事件
  2. Cheat (tldr, bropages) - Unix命令用法备忘单
  3. c# 继承,多态,new /overrid 区别, 引用父类的方法
  4. c语言详解sizeof
  5. 多线程之 CountDownLatch
  6. MFC radio button 绑定变量用法
  7. c#&amp;.NET3.0高级程序设计-02 Enum Demo
  8. 我用过的Linux命令之chmod
  9. 1.JSP入门
  10. HDU - 3068 最长回文(manacher)
  11. 使用 flow.ci 快速发布你的项目文档
  12. ansj 2.0.7 错误例子分析
  13. [ionic3.x开发记录]ios下页面过渡效果不出现的小坑
  14. cowboy源码分析(二)
  15. 在centos6.8上源码安装MySQL
  16. [NOIp2013提高组]积木大赛/[NOIp2018提高组]铺设道路
  17. C++STL二维vector指定位置排序
  18. zookeeper日志清理
  19. 数组无法使用 forEach() 方法 - 分号的重要性
  20. python 下载.whl 文件,查看已安装软件包方法

热门文章

  1. 交叉熵理解:softmax_cross_entropy,binary_cross_entropy,sigmoid_cross_entropy简介
  2. Android studio下载慢解决,使用阿里云解决(转)
  3. Idea书签管理器的使用
  4. SocketIO Server
  5. 区块链之Hyperledger(超级账本)Fabric v1.0 的环境搭建(更新)
  6. CentOS 6安装配置mongodb
  7. js获取地址栏上参数的值
  8. 理解StringBuilder
  9. 使用python画一只佩奇
  10. js 加减乘除以及四舍五入 新写法