AcWing 300. 任务安排1
题目链接
https://www.acwing.com/problem/content/302/
题解
AC代码
import java.util.*;
public class Main {
static int N = 5010;
static int[] sumT = new int[N], sumC = new int[N];
static long[] f = new long[N];
static int n, s;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
s = sc.nextInt();
for (int i = 1; i <= n; i ++) {
sumT[i] = sumT[i - 1] + sc.nextInt();
sumC[i] = sumC[i - 1] + sc.nextInt();
}
Arrays.fill(f, Long.MAX_VALUE);
f[0] = 0;
for (int i = 1; i <= n; i ++)
for (int j = 0; j < i; j ++)
f[i] = Math.min(f[i], f[j] + s * (sumC[n] - sumC[j]) + (long) sumT[i] * (sumC[i] - sumC[j]));
System.out.println(f[n]);
}
}