zoukankan      html  css  js  c++  java
  • Codeforces Round #485 (Div. 2) C. Three displays

    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;
    }
    
    
  • 相关阅读:
    layui 获取select下拉选项上自定义的属性
    TP中关联模型的使用
    安卓模仿直播中的闪动(放大缩小)的动画
    Android报错Multiple dex files define Lcom/ta/utdid2/c/a/c
    Date.parse()的坑
    Android应用加固的简单实现方案(二)
    Android应用加固的简单实现方案
    Android中ANR的触发机制-BroadcastReceiver篇
    Android中ANR的触发机制-Service篇
    Application中以标准模式启动Activity报错的原因分析
  • 原文地址:https://www.cnblogs.com/EDGsheryl/p/9157165.html
Copyright © 2011-2022 走看看