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

【题意】

【题解】

动态规划
设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. Think In java 笔记一

    本博客不再更新,很多其它精彩内容请訪问我的独立博客 今天起要读这本书了,曾经都没有认真读过书.是时候改变自己了. 如今认为不是写不出代码,而是没有想法,没有架构,要做一个大神不是写多少代码.而是要能做 ...

  2. Leetcode45:Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  3. 状态压缩dp poj 3254 hdu5045

    近来感觉状态压缩dp的强大性(灵活利用了二进制运算非常关键). . . 于是做了俩提来看看..毕竟队友是专业的dp.我仅仅是管中窥豹下而已.. 日后有机会再与之玩耍玩耍...ps:假设上天再给我一次机 ...

  4. poj1753,Flip Game,ArrayDeque&lt;Node&gt;

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30449   Accepted: 13232 Descr ...

  5. POJ2228 Naptime 环形DP

    题目大意:牛在第i个小时睡觉能够恢复U[i]点体力.睡觉时第一小时不恢复体力.一天的N小时连着下一天的1小时.求能够恢复体力的和的最大值. 定义DP[i][j][0]为前i个小时休息了j个小时,i小时 ...

  6. 45.Qt openGL实现三维绘图

    main.cpp #include <QApplication> #include <iostream> #include "tetraheadron.h" ...

  7. windows下flink示例程序的执行

    1.什么是flink Apache Flink® - Stateful Computations over Data Streams 2.启动 下载地址  我下载了1.7.2 版本  解压到本地文件目 ...

  8. HBase编程 API入门系列之工具Bytes类(7)

    这是从程度开发层面来说,为了方便和提高开发人员. 这个工具Bytes类,有很多很多方法,帮助我们HBase编程开发人员,提高开发. 这里,我只赘述,很常用的! package zhouls.bigda ...

  9. js中获取浏览器和屏幕高度

    Javascript: IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高 ...

  10. 推荐10个超棒的jQuery工具 提示插件

    脚本之家 http://www.jb51.net/article/28525.htm