CF724E Goods transportation
作者:互联网
https://www.luogu.com.cn/problem/CF724E
模拟最小割nb题
首先可以轻易得到最大流的建图,每个点往后连边,大小为\(C\),\(S\)向\(i\)连\(p_i\),\(i\)向\(T\)连\(s_i\)
因为最大流=最小割
考虑DP出最小割
设\(f[i][j]\)为考虑了前\(i\)个,有\(j\)个割掉了\(->T\)的边
然后看当前点割那条边来转移
code:
#include<bits/stdc++.h>
#define ll long long
#define N 20050
using namespace std;
int n, c;
ll a[N], b[N], f[2][N];
int main() {
scanf("%d%d", &n, &c);
for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
for(int i = 1; i <= n; i ++) scanf("%lld", &b[i]);
memset(f, 0x3f, sizeof f);
f[0][0] = 0;
for(int i = 1; i <= n; i ++) {
f[i & 1][0] = f[(i & 1) ^ 1][0] + a[i];
for(int j = 1; j <= i; j ++) f[i & 1][j] = min(f[(i & 1) ^ 1][j - 1] + b[i], f[(i & 1) ^ 1][j] + a[i] + 1ll * c * j);
}
ll ans = f[n & 1][0];
for(int i = 0; i <= n; i ++) ans = min(ans, f[n & 1][i]);
printf("%lld", ans);
return 0;
}
标签:CF724E,transportation,int,ll,最小,long,Goods,define 来源: https://www.cnblogs.com/lahlah/p/15699952.html