Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp(示例

Posted cjlhy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp(示例相关的知识,希望对你有一定的参考价值。

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;
}

/*
*/

 

以上是关于Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp(示例的主要内容,如果未能解决你的问题,请参考以下文章

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)题解报告

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)

codeforces Intel Code Challenge Final Round (div.1 + div.2 combined)