1625C - Road Optimization

#include <bits/stdc++.h>
#define x first
#define y second
#define LL long long
#define PII pair<int, int>
using namespace std;
const int N = 510;
int n, l, m;
PII a[N];
LL f[N][N];
int main() {
    scanf("%d%d%d", &n, &l, &m);
    memset(f, 0x3f, sizeof f);
    for (int i = 1; i <= n; i ++ )  scanf("%d", &a[i].x);
    for (int i = 1; i <= n; i ++ )  scanf("%d", &a[i].y);
    a[n + 1].x = l, a[n + 1].y = 0;
    f[1][0] = 0;
    for (int i = 2; i <= n + 1; i ++ ) {
        for (int j = 0; j <= m; j ++ ) {
            for (int p = i - 1; p >= 0; p -- ) {
                int num = j - (i - p - 1);
                if (num >= 0)
                    f[i][j] = min(f[i][j], f[p][num] + (a[i].x - a[p].x) * a[p].y);
            }
        }
    }
    LL res = 0x3f3f3f3f3f3f3f3f;
    for (int i = 0; i <= m; i ++ )  res = min(res, f[n + 1][i]);
    printf("%lld\n", res);
    return 0;
}
上一篇:【题解】BZOJ4669 - 抢夺


下一篇:LeetCode 0010 Regular Expression Matching