hdu 1227 Fast Food(DP线性决策)

告别第三方插件:官方Fused Library如何重塑Android库的合并与发布流程 本文详细介绍了Android官方推出的Fused Library如何替代第三方fat-aar插件,优化Android库的合并与发布流程。通过原生支持、智能依赖管理等优势,Fused Library解决了版本兼容性、依赖传递等核心痛点,提供了更稳定高效的开发体验。文章还提供了迁移实操指南和工程实践建议,帮助开发者顺利过渡到官方方案。 阅读详情

Fast Food

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


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.
 


 

Input
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.
 


 

Output
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
 


 

Source
 


 

Recommend
JGShining
 


思路:f[a][b] a到b之间只有一个补给站时的最优路径长。dp[a][b]前b个店设有a个补给站的最优值。

f[a][b]=min(f[a-1][c]+f[c+1][b])(a-1<=c<=b-1)

 

#include<iostream>
#include<cstring>
using namespace std;
const int mm=210;
const int oo=1e9;
int f[mm][mm],dp[33][mm],data[mm];
int m,n;
inline int fabs(int x)
{
    return x>0?x:-x;
}
int main()
{   int cas=0;
    while(cin>>m>>n)
    {   if(m==0&&n==0)break;
        for(int i=1;i<=m;i++)cin>>data[i];
        memset(f,0,sizeof(f));
        for(int i=1;i<=m;i++)
        for(int j=i+1;j<=m;j++)
        {   for(int k=i;k<=j;k++)
            f[i][j]+=fabs(data[(i+j)/2]-data[k]);///i到j中只设一个补给站的最优值
        }
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        for(int j=i;j<=m;j++)
        dp[i][j]=oo;
        for(int i=1;i<=m;i++)///边界
        dp[1][i]=f[1][i];
        for(int i=2;i<=n;i++)///补给站的个数
        for(int j=i;j<=m;j++)///店的个数
        { for(int k=i-1;k<j;k++)
            {int z=dp[i-1][k]+f[k+1][j];
            ///cout<<z<<"z"<<i<<" "<<j<<endl;
             dp[i][j]=z<dp[i][j]?z:dp[i][j];
            }
        }
        cout<<"Chain "<<++cas<<"\n";
        cout<<"Total distance sum = "<<dp[n][m]<<"\n";
        cout<<"\n";
    }
}


 

 

 

图像修复的万能模型:用Instruct-IPT统一解决去雨、去雾、去模糊三大难题 从原理到实战,你已经掌握了Instruct-IPT的核心逻辑和使用方法。它不仅能一站式解决多种图像退化问题,还能通过文本指令灵活控制,是图像恢复领域的“多面手”。现在,不妨找几张有雨雪、雾霾、模糊问题的图像,用Instruct-IPT亲手试试效果。当你看到模糊的图像变得清晰,被雨雾遮挡的细节重新浮现时,你会真切感受到这项技术的魅力。后续还可以尝试调整文本指令的描述方式,看看模型的响应有什么变化——探索的过程,就是你技术进阶的最好见证。 阅读详情

相关推荐

高效网络流量回放:使用tcpreplay实现多目标IP的pcap重放

本文详细介绍了如何使用tcpreplay工具高效回放网络流量pcap文件,并实现多目标IP发送。通过tcprewrite编辑报文和并行回放策略,可满足安全测试、负载测试等场景需求。文章涵盖安装、基础回放、核心技巧及性能优化,帮助读者构建真实流量压力测试环境。

weixin_29297127的博客 485

HDU 1227 Fast Food(简单二维dp)

题意是在n个餐厅之间选择k个地方修建仓库使得,各个餐厅到仓库的距离和最小。 dp[i][j] = min{dp[i][j], dp[i-1][m]+w[m+1][j]}。i表示仓库数目,j表示第几个餐厅。状态转移方程式的意思是:到达j的时候区间(i,j)上所拥有的最小的值。到达j的时候可以选择j位置上不修建仓库dp[i][j] = dp[i][j]。或者选择修仓库那么之前已经有i-1个仓库修建好

I am a slow walker, but I never walk backwards! 1154

QT下利用FFTW实现功率谱密度分析(周期图法)

写在前面 出于项目需求,需要在QT的msvc 2015编译环境下实现功率谱密度估计。 所以这个需求很直接的关键词就是 1. C++ 2. QT 3. 傅里叶变换 4. 功率谱密度估计 但是在网上搜索了很久,没有一个非常直接的答案。所以我觉得很有必要写一篇文章来说明,在QT msvc2015 32bit环境下如何实现功率谱密度估计。 本文并没有经过严格编辑,但代码是已经可以跑通的,如...

李时珍食疗志的博客 5224

zoj 1196 Fast Food 变种区间dp

好吧,其实我觉得这个题在一开始想的时候与区间dp还是有点差别的……虽然写出来跟区间dp确实差不多 Fast Food Time Limit: 2 Seconds      Memory Limit: 65536 KB The fastfood chain McBurger owns several restaurants along a highway. Recently,

ctrss的博客 954

蓝桥杯第七届省赛试题--“模拟风扇控制系统”

题目要求 功能简述 “模拟风扇控制系统”能够模拟电风扇工作,通过按键控制风扇的转动速度和定时时间,数码管实时显示风扇的工作模式,动态倒计时显示剩余的定时时间,系统主要由数码管显示、单片机最小系统、按键输入和电机控制保护电路组成,系统框图如图 1 所示: 单总线驱动程序、CT107D 单片机考试平台电路原理图以及本题所涉及到的芯片数据手册,可参考计算机上的电子文档。程序流程图及相关工程文件请以考生...

qq_43280087的博客 2666

【入门AUTOSAR网络管理测试】AUTOSAR网络管理规范需求解读

AUTOSARAutomotive Open System Architecture,汽车开放系统架构,由全球汽车制造商、部件供应商及其他电子、半导体和软件系统公司联合建立,致力于制定汽车电子软件标准的联盟。网络管理网络管理的目的是使网络中的ECU节点有序的睡眠和唤醒。在没有通信需求的时候睡眠,在需要通信的时候唤醒,可以节约汽车电池的电量。

测试领域技术分享 5178

HDU 1227 Fast Food (DP)

题意 : 有n个饭店,要求建k个供应点,要求每个供应点一定要建造在某个饭店的位置上,然后饭店都到最近的供应点拿货,求出所有饭店到最近的供应点的最短距离。 思路 : 状态转移方程:dp[i][j] = dp[i-1][k-1]+dis[k][j](i #include #include #include #include using namespace std; const

Ezereal的博客 339

【异常】Nacos 2.x 核心报错:Server check fail (gRPC 端口连不通) 排查指南 Server check fail, please check server xxx-

Nacos 2.x 的 gRPC 升级大幅提升了推送效率,但也对网络基础设施提出了更高要求。遇到。

奶爸的编程之路,也就一周冷个三天 369

UVA - 662 Fast Food 区间dp

问题 https://vjudge.net/problem/UVA-662 分析 和上一题UVA607很像,记录一下最优解的状态就行了,另外 区间【l,r】之间的最优点是(l+r)/2,这一点画图就可以看出来 代码 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <map> #include <string> #incl

zpf1998的博客 237

运行openclaw gateway install时出现Gateway install failed: Error: schtasks create failed的解决方案

本文主要介绍了运行openclaw gateway install时出现Gateway install failed: Error: schtasks create failed的解决方案,希望能对学习和使用openclaw的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 11万+

Openclaw错误排查及解决方案之:Previous run is still shutting down. Please try again in a moment.

Openclaw错误排查及解决方案之:Previous run is still shutting down. Please try again in a moment.

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 238

(HDU1227)Fast Food(DP)

どこでもドア:http://acm.hdu.edu.cn/showproblem.php?pid=1227 一共有n个商店,有k个仓库,设计仓库位置,使每个商店到,离当前商店最近,的一个仓库的距离和最小。 code#include<bits/stdc++.h> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3

ROOM 390

clock min pulse width检查

高电平脉宽 = clock fall edge到达FF/CK的时间 - clock rise edge到达FF/CK的时间;低电平脉宽 = 下一T clock rise edge到达FF/CK的时间 - clock fall edge到达FF/CK的时间。而required pulse width是根据FF/CK处的transition,根据查找表计算得到的。为什么clock transition越大,会导致required pulse width越大呢?5、 降低clock上的串扰。

芯冰乐 588

hdoj Fast Food (单线DP)n个超市中选m个建仓库使距离最短

Fast Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2535    Accepted Submission(s): 1078 Problem Description The fastfood chain M

yanghui07216的博客 984

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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

在n个点上选择k个点设为基地向n个点运送物资,使得运送物资的距离之和最小。

JSure的代码库 1398

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu1227 Fast Food--DP

原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=1227 一:原题内容 Problem Description The fastfood chain McBurger owns several restaurants along a highway. Recently, they have decided to build

半壶老酒 808

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

Fast Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2173    Accepted Submission(s): 930 Problem Description The fastfood chain

逆风的方向 更适合飞翔 2854

hdu1227 Fast Food

Fast Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1246    Accepted Submission(s): 535 Problem Description The fastfood chai

喵呜的Blog 2029

hdu 1227 fast food

Fast FoodTime Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 738     Accepted Submission(s): 338Problem DescriptionThe fastfood chain McBurger owns several restaurants along a highway. Recently, they hav

追求自由的码砖人 1782

hoj 1005 fast food

题意:有n个饭店,从中选择k个建立仓库。给出n和k以及n个饭店的x坐标,每个饭店从离他最近的仓库获得资源,使得所有饭店到仓库的距离和最小。 思路:见代码 #include #include //m[i,j]表示在前 j 个饭店建立 i 个仓库的最小距离和 //w[i,j]表示在 d[i..j]之间建立一个仓库的最小距离和 int w[201][201], m[31][201], d[201

eecrazy的专栏 2117

A. Fast Food Restaurant

滴答滴答---题目链接 A. Fast Food Restaurant time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Tired of bori...

chen_zan_yu_的博客 1224

uva 662 Fast Food (dp)

题意 一条直线马路上有n个饭店,各个坐标为di. 要在n个饭店中选择k个饭店用来建造停车场。没有建停车场的饭店,只能使用附近最近的一个停车场。 问总距离最少的建造方案,并输出。

D_Double's Journey 2206

dp问题之fast food

对于这个问题我刚开始看时,感觉没有思路,不过让我想到了了中位数,但是中位数只有一个但是这道题不只有一个,涉及商店和仓库,应该是二位dp 用dp[i][j]表示,但是i和j分别代表什么?值得考虑一下,可以让i表示仓库,j表示商店,而dp的表示前j个商店有i个仓库的所有距离和,则第i-1个仓库(即之前的一个状态)假设在第k个,要不要选这个仓库,得比较一下选前与选后距离和的变化如果选了的话如何来表示呢?迎来第二个难题,这个思想来源是中位数思想,第k+1个到j个(即第i个仓库要不要选)如果选了的话与当前的dp值在

acm菜鸟进阶 194

HDU 1227 Fast Food(经典DP)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1227 题意:在n个饭店之间选m个攻击点,使每个饭店到他的供给点的总路程的值最小 思路:在i到j这几个饭店之间建设一个供给站,供给站必须建在i到j中间的一个才能保证值最小,dp[i][j]表示在前j个饭店之间建设i个供给点 AC代码: #include #include #include

Java识堂,一个有干货的微信公众号 495

HDU1227 Fast Food(DP)

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

JOY 酷酷的专栏 361

hdu 1227 Fast Food

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1227 题目描述:   Description The fastfood chain McBurger owns several restaurants along a highway. Recently, they have decided to build several depots al...

逍遥 355
上一篇: hdu 1224 Free DIY Tour(DP多阶段决策)
下一篇: hdu 1300 Pearls(dp)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值