CF思维联系– Codeforces-987C - Three displays ( 动态规划)
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 ( 动态规划)的更多相关文章
- CF思维联系–CodeForces - 225C. Barcode(二路动态规划)
		
ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...
 - CF思维联系--CodeForces - 218C E - Ice Skating (并查集)
		
题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...
 - CF思维联系– CodeForces - 991C Candies(二分)
		
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...
 - CF思维联系–CodeForces -224C - Bracket Sequence
		
ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...
 - 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 ...
 - CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
		
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...
 - CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)
		
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...
 - Codeforces 987C. Three displays(o(n^2))
		
刚开始三重循环tle test11.后来想了个双重循环的方法. 解题思路: 1.双重循环一次,用一个一位数组存j和比j小的i的和的最小值. 2.再双重循环一次,找到比j大的数k,更新结果为ans=mi ...
 - CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
		
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...
 
随机推荐
- Java第十天,多态
			
多态 一.多态的定义: 一个对象拥有多种形态,这就是对象的多态性.也就是说多态针对的是对象.多态的前提是接口和继承(C++中实行多继承,不存在接口). 二.多态在代码中的形式: 父类 对象名 = ne ...
 - Python常见数据结构-推导式
			
推导式是一种重要的Python特性,是一种简单精炼创建Python数据结构的方式. 列表推导式,详细参考https://www.jianshu.com/p/0a269715a742 基本格式为:[表达 ...
 - Spire.Cloud 私有化部署教程(一) - CentOS 7 系统
			
Spire.Cloud支持的Linux服务器系统包括CentOS和Ubuntu(推荐使用CentOS 7和Ubuntu 18版本),本教程主要介绍如何在CentOS 7系统上实现Spire.Cloud ...
 - Struts2-学习笔记系列(9)-OGNL类型转换和类型绑定
			
HTML: <s:form action="login"> <s:textfield name="user.name" label=" ...
 - ValidForm.js的使用注意点
			
dataType的值不能为"", 否则会导致错误发生:Uncaught TypeError: Cannot read property '0' of null,http请求可以发送 ...
 - 猜数字和飞机大战(Python零基础入门)
			
前言 最近有很多零基础初学者问我,有没有适合零基础学习案例,毕竟零基础入门的知识点是非常的枯燥乏味的,如果没有实现效果展示出来,感觉学习起来特别的累,今天就给大家介绍两个零基础入门的基础案例:猜数字游 ...
 - Problem L. World Cup
			
题目大意:有A,B,C,D四个队伍,两两之间有一个比赛,假如A和B比赛,如果平局,各加一分,如果说A胜,给A加3分,不给B加分,B胜同理 给出A,B,C,D,的得分,判断形成这种局面有多少种方式. 思 ...
 - spring boot 项目 mvn clean install 报 "Unable to find main class" 的解决方法
			
按照步骤来总会解决的 检查pom.xml中是否加入了spring boot maven插件 <build> <plugins> <plugin> <group ...
 - 中间人攻击-Arp之局域网内DNS欺骗
			
基础知识 网关是啥? 网关是工作在OSI七层模型中的传输层或者应用层,用于高层协议的不同网络之间的连接,网关就好比一个房间通向另一个房间的一扇门. ARP协议 假设A(192.168.1.2)与B(1 ...
 - DataTable运用
			
DataTable dataDis.AsEnumerable().Sum(bu => bu["QtyPlan"].ConvertInt32()); ndata.TDefSty ...