思路:这个最大流-> 最小割->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; } /* */