提交时间:2024-07-03 13:28:07
运行 ID: 153478
#include<bits/stdc++.h> using namespace std; struct Node{ int a,b; }node[200]; bool cmp(Node a,Node b){ return a.a <b.a; } int f[200][200],minn=0x7fff,n,k,m; int main(){ memset(f,1145,sizeof(f)); cin>>n>>k; m=n-k; for(int i=1;i<=n;i++)f[i][1]=0; for(int i=1;i<=n;i++)cin>>node[i].a>>node[i].b; sort(node+1,node+1+n,cmp); for(int i=1;i<=n;i++)for(int j=i-1;j>=1;j--)for(int l=2;l<=min(i,m);l++)f[i][l]=min(f[i][l],f[j][l-1]+abs(node[i].b-node[j].b)); for(int i=m;i<=n;i++)minn=min(minn,f[i][m]); cout<<minn; return 0; }