#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using ll = long long;
using PII = pair<int,int>;
const int mod = 19650827;
int n,s;
int h[52];
int w[52];
int vis[52];
int sum[52];
int dp[1010][1010][2];
int res = 0x3f3f3f3f;
int main(){
cin>>n>>s;
for(int i=1;i<=n;i++){
cin>>h[i]>>w[i];
sum[i] = sum[i-1] + w[i];
}
memset(dp,0x3f,sizeof dp);
dp[s][s][0] = 0;
dp[s][s][1] = 0;
for(int len=2;len<=n;len++){
for(int i=1;i+len-1<=n;i++){
int j = i + len - 1;
dp[i][j][0] = min({dp[i+1][j][0] + (h[i+1]- h[i]) * (sum[i] + sum[n] - sum[j] ) ,
dp[i+1][j][1] + (h[j] - h[i]) * (sum[i] + sum[n] - sum[j])});
dp[i][j][1] = min({dp[i][j-1][1] + (h[j] - h[j-1]) * (sum[i-1] + sum[n] - sum[j-1]),
dp[i][j-1][0] + (h[j] - h[i]) * (sum[i-1] + sum[n] - sum[j-1])});
//cout<<dp[i][j][0];
}
}
cout<<min(dp[1][n][0],dp[1][n][1]);
}
和另一个题 Sue的小球基本一摸一样,
这种区间dp主要就是没有具体的区间了,都转化成了点点之间