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;
    }
    
    
  • 相关阅读:
    poj_1323 Game Prediction 贪心
    hdu_2391 Filthy Rich DP
    hdu_2570 迷障 贪心
    23种设计模式——结构型设计模式(7种)
    23种设计模式——创建型设计模式(5种)
    面向对象设计原则
    Android Studio常用配置
    [转]探索 Android 内存优化方法
    Java内存管理机制
    JNI与NDK简析(一)
  • 原文地址:https://www.cnblogs.com/EDGsheryl/p/9157165.html
Copyright © 2011-2022 走看看