码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #485 (Div. 2) C. Three displays

时间:2018-06-08 19:22:47      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:transform   ide   output   inf   ble   each   present   import   题解   

Codeforces Round #485 (Div. 2) C. Three displays

题目连接:

http://codeforces.com/contest/987/problem/C

Description

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 $s_i$ 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 $s_i < s_j < s_k$ should be held.

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

Sample Input

5
2 4 5 4 10
40 30 20 10 40

Sample Output

90

题意

找到一个三元组,组内元素为(i, j, k) ,有\(i<j<k\),问最小花费的三元组的花费为多少

Find a tuple whose elements fit the relationship \(i<j<k\). Each element has its cost.Find the mininum cost.

题解:

dp[i][o] 代表装了第i个物品后,共装了o个物品时的最小花费,dp[i][o] = min (dp[i][o],dp[k][o-1]+cost[i]); 其中 \(w[k]<w[i]\)

dp[i][o] represent we put the i-th element into the bag, after that there are \(o\) elements in the bag. The transform eqution is dp[i][o] = min (dp[i][o],dp[k][o-1]+cost[i]); in case of \(w[k]<w[i]\).

代码

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
int n;
pair<int,long long> p[3010];
long long dp[3010][3];
const long long INF = 0x7ffffffffffll;


int main() {
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>p[i].first;
    }
    for (int i=1;i<=n;i++) {
        cin>>p[i].second;
    }
    for (int i=1;i<=n;i++) {
        dp[i][1]=p[i].second;
        dp[i][2]=dp[i][3]=INF;
        for (int o=1;o<i;o++) {
            if (p[o].first<p[i].first) {
                dp[i][2] = min(dp[i][2],dp[o][1]+p[i].second);
                dp[i][3] = min(dp[i][3],dp[o][2]+p[i].second);
            }
        }
    }
    long long ans = INF;
    for (int i=3;i<=n;i++)
        ans = min(ans,dp[i][3]);
    cout << (ans==INF?-1:ans) << endl;
}

Codeforces Round #485 (Div. 2) C. Three displays

标签:transform   ide   output   inf   ble   each   present   import   题解   

原文地址:https://www.cnblogs.com/EDGsheryl/p/9157165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!