Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

CF724E Goods transportation

LuoGu: CF724E Goods transportation

CF: E. Goods transportation

可以建出最大流模型,最大流等于最小割,考虑最小割。

源点和汇点被割开当且仅当中间的 $n$ 个点不同时连接源点和汇点。一个点如果不和源点连通,代价为和源点连接的边的代价以及每条前面和源点连接的点的边 $c$ 的代价;不和汇点连通,代价为和汇点连接的边的代价。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <algorithm>
using namespace std;
template <class Type>
void read (Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0';
flag && (x = ~x + 1);
}
template <class Type>
void write (Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar('0' + x % 10);
}
typedef long long LL;
const int N = 1e4 + 10;
int n;
LL m, w[N], v[N], f[N];
int main ()
{
read(n), read(m);
for (int i = 1; i <= n; i++)
read(w[i]);
for (int i = 1; i <= n; i++)
read(v[i]);
for (int i = 1; i <= n; i++)
{
f[i] = f[i - 1] + v[i];
for (int j = i - 1; j; j--)
f[j] = min(f[j - 1] + v[i], f[j] + w[i] + m * j);
f[0] += w[i];
}
LL res = 1e18;
for (int i = 0; i <= n; i++)
res = min(res, f[i]);
write(res);
return 0;
}