ZOJ 3469Food Delivery

Source: Internet
Author: User

Main topic:

There are n individuals, living in a straight line. I personal coordinates is XI, the street has a takeaway restaurant location is X, now the restaurant staff to give everyone on the street food, sent back to the restaurant, the speed of delivery is V, everyone has an unsatisfactory value, when the person delivered a meal a minute every night, then this person's dissatisfaction value increases bi. The total unsatisfied value is required to be minimal. ===============================================================================================================
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespaceStd;typedefLong LongLL;ConstLL INF = 1e9+7;ConstLL MAXN = 1e3+5;ConstLL MOD = 1e9+7;intdp[2][MAXN][MAXN], SUM[MAXN];structnode{intX, B; BOOLFriendoperator<(node A, node B) {returnA.x <b.x; }} P[MAXN];intMain () {intN, v, x;  while(CIN >> N >> v >>x) { for(intI=1; i<=n; i++) Cin>> P[i]. X >>P[i].        B P[n+1]. x = x, p[n+1]. B =0; N++; Memset (DP,0,sizeof(DP)); memset (SUM,0,sizeof(sum)); Sort (P+1, p+1+N); sum[0] =0;  for(intI=1; i<=n; i++) Sum[i]= sum[i-1] +P[i].        B intStar;  for(intI=0; i<=n+1; i++)         for(intj=0; j<=n+1; J + +) dp[0][I][J] = dp[1][I][J] =INF;  for(intI=1; i<=n; i++)        {            if(P[i]. X = =x) {Star=i;  Break; }} dp[0][star][star] = dp[1][star][star] =0;  for(intI=star; i>=1; i--)         for(intJ=star;  j<=n; J + +) {dp[0][i][j] = min (dp[0][I][J], dp[0][i+1][J] + (p[i+1]. X-p[i]. X) * (sum[n]-sum[j]+sum[i])); dp[0][i][j] = min (dp[0][I][J], dp[1][i+1][J] + (P[j]. X-p[i]. X) * (sum[n]-sum[j]+Sum[i]))            ; dp[1][i][j] = min (dp[1][I][J], dp[0][i][j-1] + (P[j]. X-p[i]. X) * (sum[n]-sum[j-1]+sum[i-1]) ); dp[1][i][j] = min (dp[1][I][J], dp[1][i][j-1] + (P[j]. x-p[j-1]. X) * (Sum[n]-sum[j-1] + sum[i-1]) ); } printf ("%d\n", Min (dp[0][1][n],dp[1][1][n]) *v); }    return 0;}

ZOJ 3469Food Delivery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.