【链接】 我是链接,点我呀:)

【题意】

【题解】

动态规划
设dp[i][j]表示前i个数字,选了j个的最小花费。
dp[i][j] = min(dp[k][j-1]+b[i]);//其中a[i]>a[k]且ka[k]的位置k才有可能。
复杂度O(N^2)

【代码】

#include <bits/stdc++.h>

using namespace std;

const int N = 3e3;
const int INF = 4e8; int n;
int a[N+10],b[N+10];
int dp[N+10][4]; int main()
{
#ifdef LOCAL_DEFINE
freopen("rush.txt","r",stdin);
#endif // LOCAL_DEFINE
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= n;i++) cin >> b[i];
for (int i = 1;i <= 3;i++)
for (int j = 1;j <= n;j++)
dp[j][i] = INF;
for (int i = 1;i <= n;i++) dp[i][1] = b[i]; for (int j = 2;j <= 3;j++)
for (int i = j;i <= n;i++)
for (int k = j-1;k <= i-1;k++)
if (a[i]>a[k] && dp[i][j]>dp[k][j-1]+b[i]){
dp[i][j] = dp[k][j-1]+b[i];
}
int ans = INF;
for (int i = 3;i <= n;i++)
ans = min(ans,dp[i][3]);
if (ans==INF)
cout<<-1<<endl;
else
cout<<ans<<endl; return 0;
}

【CodeForces 987C】Three displays的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【74.00%】【codeforces 747A】Display Size

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. XTU OJ 1207 Welcome to XTCPC (字符串签到题)

    Problem Description Welcome to XTCPC! XTCPC start today, you are going to choose a slogan to celebra ...

  2. BNU 34986 Football on Table

    "Bored? Let's play table football!" The table football is played on a rectangular table, u ...

  3. Git与SVN区别 \git学习

    http://blog.csdn.net/w13770269691/article/details/38705473/ https://git-scm.com/book/zh/v2

  4. LeetCode96_Unique Binary Search Trees(求1到n这些节点能够组成多少种不同的二叉查找树) Java题解

    题目: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For e ...

  5. vim分屏功能

    转载,来自http://coolshell.cn/articles/1679.html 本篇文章主要教你如何使用 Vim 分屏功能. 分屏启动Vim 使用大写的O参数来垂直分屏. vim -On fi ...

  6. Linux安装sshfs挂载远程目录到本地及卸载

    挂载远程目录的方式很多,这里把sshfs记录一下备忘.Linux用sshfs挂载远程目录到本地 安装sshfs 在Ubuntu下,只需要使用 $ sudo apt-get install sshfs ...

  7. Android常用的一些make命令【转】

    本文转载自:http://blog.csdn.net/liuxd3000/article/details/39181377 1.make -jX  X表示数字,这个命令将编译Android系统并生成镜 ...

  8. k8s traefik ingress tls

    使用下面的 openssl 命令生成 CA 证书: $ openssl req -newkey rsa:2048 -nodes -keyout tls.key -x509 -days 365 -out ...

  9. TCP心跳包

    所谓的心跳包就是客户端定时放送简单的信息给服务器端,告诉它我还在而已.代码就是每 隔几分钟发送一个固定信息给服务器端,服务器端回复一个固定信息.如果服务器端几分钟后没有收到客户端信息则视客户端断开.比 ...

  10. SMTP协议详解

    简单邮件传输协议 (Simple Mail Transfer Protocol, SMTP) 是在Internet传输email的事实标准. SMTP是一个相对简单的基于文本的协议.在其之上指定了一条 ...