ACM思维题训练集合
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 si 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 si<sj<sk should be held.

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

Input
The first line contains a single integer n (3≤n≤3000) — the number of displays.

The second line contains n integers s1,s2,…,sn (1≤si≤109) — the font sizes on the displays in the order they stand along the road.

The third line contains n integers c1,c2,…,cn (1≤ci≤108) — the rent costs for each display.

Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i<j<k such that si<sj<sk.

Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
一看到这题,我觉得像是个背包,实际上差不多,只不过就是有了限制条件,后选的序号一定大于之前的序号,且给定的S[i]也需要大于之前选的。然后这个题我觉得数据有点水n2n^2n2的复杂度竟然能这么快。

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{char ch = getchar();x = 0;int f = 1;while (ch < '0' || ch > '9')f = (ch == '-' ? -1 : f), ch = getchar();while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();x *f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
//---------------https://lunatic.blog.csdn.net/-------------------//
const int N = 3005;
const int INF = 0x3f3f3f3f;
int s[N], cost[N], maxi[N];
int dp[N][10], weight[N][10];
int main()
{int n;read(n);rep(1, n + 1, i){read(s[i]);}rep(1, n + 1, i){read(cost[i]);}memset(dp, 0x3f, sizeof(dp));//rep(0, n + 1, i)  weight[i] =s[i];rep(1, n, i){dp[i][1]=cost[i];weight[i][1]=s[i];for (int j =2; j <= 3; j++){for (int k = i+1; k <= n; k++)if (s[k] > weight[i][j-1]){//cout<<1;if (dp[k][j] > dp[i][j - 1] + cost[k]){//cout<<2;dp[k][j] = dp[i][j - 1] + cost[k];weight[k][j] = s[k];}}}}int ans = INF;rep(1, n + 1, i)ans = min(ans, dp[i][3]);if (ans == INF)puts("-1");else{wi(ans);P;}
}

CF思维联系– Codeforces-987C - Three displays ( 动态规划)相关推荐

  1. CF思维联系–CodeForces - 225C. Barcode(二路动态规划)

    ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...

  2. CF思维联系--CodeForces - 218C E - Ice Skating (并查集)

    题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...

  3. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  4. CF思维联系–CodeForces -224C - Bracket Sequence

    ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...

  5. CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)

    ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...

  6. CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)

    ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...

  7. CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)

    ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...

  8. Codeforces 987C. Three displays(o(n^2))

    刚开始三重循环tle test11.后来想了个双重循环的方法. 解题思路: 1.双重循环一次,用一个一位数组存j和比j小的i的和的最小值. 2.再双重循环一次,找到比j大的数k,更新结果为ans=mi ...

  9. 【CodeForces - 987C 】Three displays (dp,最长上升子序列类问题,三元组问题)

    题干: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaik ...

最新文章

  1. 扁平化职能管理三部曲
  2. 教你一招---如何把桌面弄到D盘
  3. 微信小程序 html css xml,微信小程序 使用towxml解析html流程及踩坑记录
  4. sparkshelljarlib_spark-submit 应用程序第三方jar文件
  5. Linux远程管理协议相关知识介绍
  6. Educational Codeforces Round 101 (Rated for Div. 2) C. Building a Fence 思维取范围
  7. linux内核设计与实现 怎么读,《Linux内核设计与实现》读书笔记(一)
  8. ueditor 在线附件和在线图片路径错误BUG补丁
  9. 13 CO配置-控制-内部订单-定义定单类型
  10. python编写科学计算器_Python实现的科学计算器功能示例
  11. linux下文本文件转换编码格式的方法
  12. 综合后端各种类型文件
  13. decimal类型对象里面定义什么类型_数据库数据类型decimal理解
  14. caffee 安装教程
  15. 报童问题(3)-深入分析
  16. wpsmac和pc版的区别_Mac系统下金山WPS和微软Office 哪个更好更好用
  17. c语言写死循环程序,通过简单的例子看c程序死循环
  18. 反汇编工具ollydbg ida
  19. 能源数字化,未来四十年看什么?
  20. 写公众号的一些【奇葩经历】以及【思考】

热门文章

  1. list python 访问 键值对_基础|Python常用知识点汇总(中)
  2. 3.21日 爬虫小计
  3. 分享一下dudu回答的一个方法
  4. 快讯千树资本投资柒小佰 踏入儿童出行消费领域...
  5. JHipster生成微服务架构的应用栈(一)- 准备工作
  6. 新媒体视频导演 - 美学基础 todo
  7. 查看Linux服务器的CPU详细信息
  8. PHP-RSA加密跨域通讯实战
  9. JS读取JSON数据
  10. 企业能为员工储蓄点什么呢