zoukankan      html  css  js  c++  java
  • Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E

    E - Goods transportation

    思路:这个最大流-> 最小割->dp好巧妙哦。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PII pair<int, int>
    #define PLI pair<LL, int>
    #define ull unsigned long long
    using namespace std;
    
    const int N = 1e4 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    
    int n, c, cur, p[N], s[N];
    LL dp[2][N];
    int main() {
        scanf("%d%d", &n, &c);
        for(int i = 1; i <= n; i++) scanf("%d", &p[i]);
        for(int i = 1; i <= n; i++) scanf("%d", &s[i]);
        memset(dp[cur], INF, sizeof(dp[cur]));
        dp[cur][0] = 0;
        for(int i = 1; i <= n; i++) {
            cur ^= 1;
            memset(dp[cur], INF, sizeof(dp[cur]));
            dp[cur][0] = dp[cur^1][0] + p[i];
            for(int j = 1; j < i; j++) {
                dp[cur][j] = min(dp[cur^1][j] + 1ll*j*c + p[i], dp[cur^1][j-1] + s[i]);
            }
            dp[cur][i] = dp[cur^1][i-1] + s[i];
        }
        LL ans = INF;
        for(int i = 0; i <= n; i++) ans = min(ans, dp[cur][i]);
        printf("%lld
    ", ans);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    Dice 5 ==> dice 7
    Dice 7 ==> dice 5
    100 floors 2 eggs
    Determine overlapping rectangles
    Product of integers
    Maximum profit of stocks
    样式表
    20170508
    2017年05月07
    The second day of school
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9741063.html
Copyright © 2011-2022 走看看