日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 ( 动态规划)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。