这道题主要就是费用提前计算
代码
#include <bits/stdc++.h>
using namespace std;const int N = 5010;int t[N], c[N], f[N];int main()
{int n, s;cin >> n >> s;for (int i = 1; i <= n; i ++ ){cin >> t[i] >> c[i];t[i] += t[i - 1];c[i] += c[i - 1];}memset(f, 0x3f, sizeof f);f[0] = 0;for (int i = 1; i <= n; i ++ ){for (int j = 0; j < i; j ++ ){f[i] = min(f[i], f[j] + (c[i] - c[j]) * t[i] + (c[n] - c[j]) * s);}}cout << f[n] << endl;return 0;
}