NC19980. [HAOI2010]订货
描述
输入描述
第1行:n, m, S (0 ≤ n ≤ 50, 0 ≤ m ≤ 10, 0 ≤ S ≤ 10000)第2行:U1 , U2 , ... , Ui , ... , Un (0 ≤ Ui ≤ 10000)第3行:d1 , d2 , ..., di , ... , dn (0 ≤ di ≤ 100)
输出描述
只有1行,一个整数,代表最低成本
示例1
输入:
3 1 1000 2 4 8 1 2 4
输出:
34
C++11(clang++ 3.9) 解法, 执行用时: 8ms, 内存消耗: 8956K, 提交时间: 2020-09-22 19:14:46
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 55, S = 10000+5; int n, m, s, u[N], d[N]; ll f[N][S], minn[N][S]; void work() { scanf("%d%d%d", &n, &m, &s); for (int i = 1; i <= n; i++) scanf("%d", &u[i]); for (int i = 1; i <= n; i++) scanf("%d", &d[i]); memset(f, 127/3, sizeof(f)); f[0][0] = 0; memset(minn, 127/3, sizeof(minn)); for (int i = 1; i <= n; i++) { for (int j = 0; j <= s; j++) minn[i][j] = min(minn[i][j-1], f[i-1][j]-1ll*j*d[i]); for (int j = 0; j <= s; j++) f[i][j] = minn[i][min(s, j+u[i])]+1ll*j*(d[i]+m)+1ll*u[i]*d[i]; } printf("%lld\n", f[n][0]); } int main() {work(); return 0; }