You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 5010;
int t[N], c[N];
int f[N][N];
int n, s;
/**
5
1
1 3
3 2
4 3
2 3
1 4
153
5000*5000=25000000
25000000 * 4byte=100000000 byte = 100000 kb = 100 mb >64mb
MLETLEMLE
*/
int main() {
// 任务个数与启动时间
cin >> n >> s;
for (int i = 1; i <= n; i++) {
cin >> t[i] >> c[i];
t[i] += t[i - 1]; // t数组自带前缀和
c[i] += c[i - 1]; // c数组自带前缀和
}
/* 1、为什么这样初始化
f[i][j] = min(f[i][j], f[k][j - 1] + (j * s + t[i]) * (c[i] - c[k]));
f[i][j]ij
k
j-1~0
j-1=0,00,0
*/
memset(f, 0x3f, sizeof f);
memset(f[0], 0, sizeof f[0]);
// 2、开始填表
for (int i = 1; i <= n; i++) // i个任务
for (int j = 1; j <= i; j++) // j个阶段注意j的上界一个阶段1个任务是极限此时i=j
for (int k = j - 1; k < i; k++) // 最后一个阶段的起点k
f[i][j] = min(f[i][j], f[k][j - 1] + (s * j + t[i]) * (c[i] - c[k])); // 前缀和 \sum_{a=k+1}^{i}c[a]
/*
3
f[n]n,123...n,1,nn
*/
int res = INF;
for (int i = 1; i <= n; i++) res = min(res, f[n][i]);
cout << res << endl;
return 0;
}