不用了 **我是傻子**
```cpp
#include <iostream>
#include <cstdio>
using namespace std;
#define Rep(i, j, k) for (int i = j; i <= k; i++)
#define ll long long
#define INF 2147483647
ll f[60][60][2], sum_pow[60] = { 0 }, pos[60] = { 0 };
int n, c;
int main() {
scanf("%d %d", &n, &c);
int pow;
Rep(i, 1, n) {
Rep(j, 1, n) f[i][j][0] = f[i][j][1] = INF;
scanf("%d %d", &pos[i], &pow);
sum_pow[i] = sum_pow[i - 1] + pow;
}
int l, r;
f[c][c][0] = f[c][c][1] = 0;
Rep(k, 2, n) {
Rep(l, c - k + 1, c) {
r = l + k - 1;
if (r > n) break;
if (l < 1) continue;
if (l + 1 <= c) {
f[l][r][0] = min(
f[l + 1][r][0] + (pos[l + 1] - pos[l]) * (sum_pow[l] + sum_pow[n] - sum_pow[r]),
f[l + 1][r][1] + (pos[r] - pos[l]) * (sum_pow[l] + sum_pow[n] - sum_pow[r])
);
}
if (r - 1 >= c) {
f[l][r][1] = min(
f[l][r - 1][1] + (pos[r] - pos[r - 1]) * (sum_pow[l - 1] + sum_pow[n] - sum_pow[r - 1]),
f[l][r - 1][0] + (pos[r] - pos[l]) * (sum_pow[l - 1] + sum_pow[n] - sum_pow[r - 1])
);
}
}
}
printf("%lld", min(f[1][n][0], f[1][n][1]));
return 0;
}
```
~~状态转移做乘法的时候有两行忘记加括号了~~
by Blazar北极星 @ 2020-02-23 15:50:29