hdoj 1227 Fast Food 【dp】

原创 2015年11月19日 20:34:25

Fast Food

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2521    Accepted Submission(s): 1071

Problem Description
The fastfood chain McBurger owns several restaurants along a highway. Recently, they have decided to build several depots along the highway, each one located at a restaurant and supplying several of the restaurants with the needed ingredients. Naturally, these depots should be placed so that the average distance between a restaurant and its assigned depot is minimized. You are to write a program that computes the optimal positions and assignments of the depots.

To make this more precise, the management of McBurger has issued the following specification: You will be given the positions of n restaurants along the highway as n integers d1 < d2 < ... < dn (these are the distances measured from the company's headquarter, which happens to be at the same highway). Furthermore, a number k (k <= n) will be given, the number of depots to be built.

The k depots will be built at the locations of k different restaurants. Each restaurant will be assigned to the closest depot, from which it will then receive its supplies. To minimize shipping costs, the total distance sum, defined as

must be as small as possible.

Write a program that computes the positions of the k depots, such that the total distance sum is minimized.

The input file contains several descriptions of fastfood chains. Each description starts with a line containing the two integers n and k. n and k will satisfy 1 <= n <= 200, 1 <= k <= 30, k <= n. Following this will n lines containing one integer each, giving the positions di of the restaurants, ordered increasingly.

The input file will end with a case starting with n = k = 0. This case should not be processed.

For each chain, first output the number of the chain. Then output a line containing the total distance sum.

Output a blank line after each test case.

Sample Input
6 3 5 6 12 19 20 27 0 0

Sample Output
Chain 1 Total distance sum = 8
#define mem(x,y) memset(x,y,sizeof(x))
#define inf 0x3f3f3f3f
#define N 220
using namespace std;

int dis[N],dp[N][N],cost[N][N];

int main()
    int n,m;
    int cnt=0;
        int i,j,k;
            printf("Chain %d\nTotal distance sum = %d\n\n",++cnt,dp[m][n]);
   // system("pause");
    return 0;

版权声明:博主情人,外人误碰!!! http://blog.csdn.net/qq_21654717/article/details/49933399

[ACM] HDU 1227 Fast Food (经典Dp)

Fast Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...
  • sr19930829
  • sr19930829
  • 2014年10月09日 15:35
  • 1814

【DP|数学+预处理】HDU-1227 Fast Food

  • u012325552
  • u012325552
  • 2014年11月28日 15:48
  • 811

HDU 1227 Fast Food DP *

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1227 状态很好定义,关键是怎么递推,加入一个仓库后的影响怎么算出来 思路:http://www.c...
  • qq_34446253
  • qq_34446253
  • 2016年10月04日 17:10
  • 132

HDU 1227 Fast Food DP

http://acm.hdu.edu.cn/showproblem.php?pid=1227 题目大意: n个饭店在一条直线上,要在这条直线上建立k个仓库,使各个仓库到商店距离和最小。(仓...
  • murmured
  • murmured
  • 2013年12月14日 11:08
  • 625

HDU 1227 Fast Food (DP)

题意 : 有n个饭店,要求建k个供应点,要求每个供应点一定要建造在某个饭店的位置上,然后饭店都到最近的供应点拿货,求出所有饭店到最近的供应点的最短距离。 思路 : 状态转移方程:dp[i][j]...
  • Ezereal
  • Ezereal
  • 2016年07月29日 22:56
  • 131

HDU 1227 Fast Food(dp)

  • qq_33901573
  • qq_33901573
  • 2016年09月26日 20:50
  • 84

hdu 1227 Fast Food(dp)

http://acm.hdu.edu.cn/showproblem.php?pid=1227 转载: 在n个商店中建m个仓库,使各个商店到仓库的路程之和最小,商店到哪个仓库是有选择...
  • u013081425
  • u013081425
  • 2014年03月04日 21:46
  • 768

(DP) HDU 1227 Fast Food

/*dp[i][j]=min(dp[i][j],dp[k][j-1]+d[k+1][i]) dp[k][j-1] 表示从k个饭店中建立j-1个仓库 d[k+1][i] 表示从第k+...
  • wu_yangjun
  • wu_yangjun
  • 2013年07月30日 17:16
  • 289

hdu 1227 Fast Food

主题思想: 动态规划首先 对于一组升序的数,选择仓库在中位数的位置能是距离最短,这种思路以前遇到过。 动态规划转移方程 : 就是这个不好想啊。 首先题目要求的是距离。 那么就用dp表示距离,因为好多...
  • the_conquer_zzy
  • the_conquer_zzy
  • 2017年08月31日 22:41
  • 79

HDU 1227 Fast Food

 Fast Food Problem DescriptionThe fastfood chain McBurger owns several restaurants along a highway. ...
  • qq503884564
  • qq503884564
  • 2011年01月24日 11:39
  • 324
您举报文章:hdoj 1227 Fast Food 【dp】