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;
    }
    
    
  • 相关阅读:
    【BZOJ】1006: [HNOI2008]神奇的国度 弦图消除完美序列问题
    【BZOJ】1015: [JSOI2008]星球大战starwar
    poj 2001 Shortest Prefixes trie入门
    hdu 1251 统计难题 trie入门
    hdu 4570 Multi-bit Trie 区间DP入门
    Lucas定理的理解与应用
    hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)
    组合数模板
    如何使用弹窗来让用户订阅电子杂志
    分享一则电子邮件营销案例
  • 原文地址:https://www.cnblogs.com/EDGsheryl/p/9157165.html
Copyright © 2011-2022 走看看