ZOJ 3469 Food Delivery (interval dp, classic)

Source: Internet
Author: User

Test instructions

On the x-axis, there is a takeaway restaurant, there are n customers on the x-axis on the different coordinates and called the takeaway, everyone's temper is different, every 1 minutes did not receive the takeaway will increase the fi point rage value, the outside selling small brother's car is a speed of v-1/minutes, ask how the order will let all customers anger value and minimum? Output the sum of rage values!

Ideas:

This problem is very classic, a more realistic model.

Casually draw the know that the brother can suddenly go to the left suddenly to the right, round trip is also possible, depending on the customer's anger coefficient fi. Then, when considering an interval [l,r], any of its sub-ranges must have been considered. Now consider where the interval [l,r] can be transferred to, and obviously can be transferred to [L-1,r] and [l,r+1], that is, to send 1 people out of the range of takeout. Since the delivery interval [l,r] All takeout may stop at left/right, the resulting DP value is different, so you can add 1 D to distinguish the post-stop position, set to DP[L][R][0/1] to record the sum of anger.

This is not done, and if only the sum of the rage values of the customers of the current interval [l,r] is taken into account, no matter how it is recorded or not, the transfer is difficult (and this is a more ingenious place). But if you put the anger value of other non-delivery customers into the DP value first and then transfer, such as the interval [l,r] transfer to [l,r+1], then [1,L-1] and [r+2,n] These customers are still selling, every 1 minutes their rage value is also increasing, can add to [l,r+1] of the DP value.

Is it possible that dp[l][r][0] will be transferred to Dp[l][r+1][0]? That is, from L to r+1 back to the L place. After reckoning, it is not necessary, not difficult to think about.

1 //#include <bits/stdc++.h>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <map>7#include <algorithm>8#include <vector>9#include <iostream>Ten #definePII pair<int,int> One #defineINF 0x3f3f3f3f A #defineLL Long Long - using namespacestd; - Const DoublePI = ACOs (-1.0); the Const intn=1010; - structnode - { -     intx, F; + }p[n]; - intdp[n][n][2], sum[n]; + intN, V, X, POS; AInlineintCMP (node A,node b) {returna.x<b.x;} at  - voidInitintPOS) - { -sum[0]=0; -      for(intI=1; i<=n; i++) sum[i]=sum[i-1]+p[i].f; -  in      for(intI=1; i<=n; i++)//Initialize -          for(intJ=i; j<=n; J + +) todp[i][j][0]=dp[i][j][1]=INF; +dp[pos][pos][0]=dp[pos][pos][1]=0; - } the  * intCalintPOS) $ {Panax Notoginseng      for(intJ=pos; j<=n; J + +) -     { the          for(intI=pos; I>0; i--) +         { A             intf=sum[i-1]+SUM[N]-SUM[J];//Sum of f values * the             intl=dp[i][j][0], r=dp[i][j][1]; +  -dp[i-1][j][0]=min (dp[i-1][j][0], l+f* (p[i].x-p[i-1].x));//Go left $dp[i-1][j][0]=min (dp[i-1][j][0], r+f* (p[j].x-p[i-1].x)); $  -dp[i][j+1][1]=min (dp[i][j+1][1], l+f* (p[j+1].x-p[i].x));//go right -dp[i][j+1][1]=min (dp[i][j+1][1], r+f* (p[j+1].x-p[j].x)); the         } -     }Wuyi     returnMin (dp[1][n][0], dp[1][n][1])*V; the } -  Wu intMain () - { About     //freopen ("Input.txt", "R", stdin); $      while(~SCANF ("%d%d%d",&n,&v,&x)) -     { -          for(intI=1; i<=n; i++) -scanf"%d%d", &p[i].x, &p[i].f); A  +P[++n].x=x, p[n].f=0;//Add a restaurant theSort (p+1, p+n+1, CMP); -  $          for(intI=1; i<=n; i++) the         { the             if(p[i].x==x)//Find a restaurant the             { the init (i); -Cout<<cal (i) <<Endl; in                  Break; the             } the         } About     } the     return 0; the}
AC Code

ZOJ 3469 Food Delivery (interval dp, classic)

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.