Food Delivery
题意:外卖送饭给N个顾客,要求他们不满度和最小,没人不满度=等待时间*耐心值
#include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define maxn 1010 int n,x,v,dp[maxn][maxn][3],sum[maxn]; struct node{ int x,b; }a[maxn]; int cmp(node u,node v){ return u.x<v.x; } int main(){ while(scanf("%d%d%d",&n,&v,&x)!=EOF){ memset(dp,127/3,sizeof(dp)); memset(a,0,sizeof(a)); for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].b); n++;a[n].x=x,a[n].b=0; sort(a+1,a+n+1,cmp);int tmp; for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i].b; for(int i=1;i<=n;i++)if(a[i].x==x){tmp=i;break;} dp[tmp][tmp][0]=0,dp[tmp][tmp][0]=0; for(int i=tmp;i>=1;i--){ for(int j=tmp;j<=n;j++){ dp[i][j][0]=min(dp[i][j][0],dp[i+1][j][0]+(sum[n]-sum[j]+sum[i])*(a[i+1].x-a[i].x)); dp[i][j][0]=min(dp[i][j][0],dp[i+1][j][1]+(sum[n]-sum[j]+sum[i])*(a[j].x-a[i].x)); dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][0]+(sum[n]-sum[j-1]+sum[i-1])*(a[j].x-a[i].x)); dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][1]+(sum[n]-sum[j-1]+sum[i-1])*(a[j].x-a[j-1].x)); } } printf("%d ",min(dp[1][n][0],dp[1][n][1])*v); } }