uva 10003 - Cutting Sticks 动态规划

动态规划算法应用之 切割木棍问题 切割木棍问题 给定一根长度为 n 英尺的木棍和一个价值数组 value[],数组中的第 i 个元素值 v 代表木棍长长度为 i 时,其价值为 v。现在要求将木棍切割成若干段,使得切割后所有木棍的价值总和最大。例如给定长度为 8 的木棍,对于下图的价值数组,当把它切割成两段长度为 2 和 6 的木棍时,两木棍的价值总和最大,为 22。 而对于同样的长度 8,如果价值数组如下,那么切割成 8 段长度为 1 的木棍时取得最大价值 24=3*8。 分析:先考虑只切割一次的情况,因为切割的位置只有 n 阅读详情

题目

换一个思路,剪不好处理,拼接怎么样?这就转化成了“合并石子”的问题。有n堆石子,排成一列,每次可以将相邻两堆合并,合并的费用为合并后得到新的一堆石子的石子数,将所有石子合并成一堆,求最小的合并费用。

那这题怎么写对拍呢?给出木棍的范围[a,b),找出这段范围内可以剪的位置,枚举剪的位置,转化为另一个规模较小的子问题,这又可以用动态规划来做。但是其复杂度是O(N*I*I),I为木棍的最大长度,N为测试样例。uva会冷冰冰地告诉你"time limit exceeded"。但不失为一个好的对拍方案。

dp:

#include<cstdio>
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<ctime>
#include<iostream>
#define INF 1<<30
using namespace std;
const int maxn=50+10;
int sum[maxn];
int f[maxn][maxn];

int dp(int i,int j)
{
	int &ans=f[i][j];
	if(ans!=-1) return ans;
	if(i==j) return ans=0;//只有一根,不用拼接 
	ans=INF;
	for(int k=i;k<=j-1;k++)//枚举最后一次拼接位置 
	  ans=min(ans,dp(i,k)+dp(k+1,j));
  ans+=sum[j]-sum[i-1];
  return ans;
}//

int main()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
#endif
	int i,j;
	int I,n;
	while(scanf("%d",&I)==1 && I)
	{
		scanf("%d",&n);
		sum[0]=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&sum[i]);
		}
		sum[n+1]=I;
		//for(i=0;i<=n+1;i++) printf("%d\n",sum[i]);
		memset(f,-1,sizeof(f));
		printf("The minimum cutting is %d.\n",dp(1,n+1));//最后共有n+1根木头 
	}
	//printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
  return 0;
}

/*
*/

对拍:

#include<cstdio>
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<ctime>
#include<iostream>
using namespace std;
const int INF=1<<30;
const int maxn=50+10;
const int maxi=1000+10;
int c[maxn],n;
int f[maxi][maxi];

int dfs(int a,int b)//[a,b)
{
	int &ans=f[a][b];
	if(ans!=-1) return ans;
	int pos[maxn],pn=0;
	int i;
	for(i=0;i<n;i++)
	  if(c[i]>a && c[i]<b)
	  {
  		pos[pn++]=c[i];
  	}
	if(pn==0) return 0;
	ans=INF;
	for(i=0;i<pn;i++)
	  ans=min(ans,dfs(a,pos[i])+dfs(pos[i],b));
  ans+=b-a;
  return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
#endif
	int i,j;
	int I;
	while(scanf("%d",&I)==1 && I)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++) scanf("%d",&c[i]);
		memset(f,-1,sizeof(f));
		printf("The minimum cutting is %d.\n",dfs(0,I));
	}
	//printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
  return 0;
}

/*
*/

钢条切割-【算法导论-动态规划】 对以上的价格表样例,进行模拟切割: r1 = 1,切割方案1 = 1(无切割) r2 = 5,切割方案2 = 2(无切割) r3 = 8, 切割方案3 = 3(无切割) r4 = 10, 切割方案4 = 2 + 2 r5 = 13, 切割方案5 = 2 + 3 r6 = 17, 切割方案6 = 6(无切割) r7 = 18, 切割方案7 = 1 + 6或7 = 2 + 2 + 3 r8 = 22, 切割方案8 = 2 + 6 r9 = 25, 切割方案9 = 3 + 6 r10 = 30,切割方案10 = 10(无切割) 可能现在大家对这种切割比较不耐烦,或者是有的数并不是那么好,怎么办? 这时有个很好的思想,就是动态规划,之前模拟切割尽管结果出来的很简单,但是过程却依然很复杂; 比如r7,它有很多切割方案,1-6,2-5,3-4,2-2-3,1-1-5等等,这些过程如何自己来模拟的话实在是太费时间,但是我们想在切割7的时候前面都已经完成了,我们可以在前面的基础上进行切割,这时只要考虑1-6,2-5,3-4即可,比如现在的1-6就包括了之前的1-1-5,1-2-4等的切割方案; 立即下载

相关推荐

自动化测试-自愈技术

随着人工智能的发展,作为一名软件测试工程师,相信大家都会思考如何把这一前沿技术引入到我们的自动化测试当中,想一万遍不如做一遍。,传递当前页面状态,获取之前成功的定位器路径,比较它们,并生成修复的定位器列表。如果修复成功,我们可以使用 Healenium Idea 插件更新我们的自动化测试代码:插件使用修复定位器寻找修复和更新测试代码。的旧定位器去定位按钮的时候,脚本就会报错,提示 “NoSuchElement”的错误异常。现在,我们假设开发人员变更了应用程序的UI界面,改变了这个按钮的id属性,从。

qq_58223744的博客 2660

算法设计与分析基础 第八章谜题

习题8.1 6.切割木棍问题 为下列问题设计一个动态规划算法。已知小木棍的销售价格pi和长度i相关,i=1,2,…,n,如何把长度为n的木棍切割为若干根长度为整数的小木棍,使得所获得的总销售价格最大?该算法的时间效率和空间效率各是多少? 解答:令长度为n的木棍能获得的最大价格为profit[n],递推公式为:profit[n] = max(pi[i] + profit[length - seg...

勤奋乐观的博客 6977

Simulink模块库介绍(一)——信号源模块

Simulink模块库介绍(一)——信号源模块库目录Clock模块Digital Clock模块Band-Limited White Noise模块 目录 simulink模块库中提供了丰富的信号源模块组。逐一介绍,算是对之前做个总结吧 Clock模块 通过时钟模块,输出的时间作为判断呢,如下图,前2s之前为高斯白噪声,后2s为正弦曲线,共计10s。 Digital Clock模块 数字时钟模块主要用于离散系统的计时,sample time表示采用时间,如下图:分别是1s和0.5s的采样时间 Band-

5万+

【算法学习】切割木棍问题——动态规划

问题描述: 假设,有一条长度为n的木棍,已知木棍的销售价格Pi与木棍长度i有关,i = 1,2,3,...n.问,怎样切割能获得最大收益。 长度为0的木棍收益肯定是0了,即profit[0] = 0. 切割长度(seg) 1 2 3 4 5 6 7 8 9 10 销售价格(pi) 1 5 8 9 10 17 17 20 24

依然那霖哥 1万+

abaqus运行报错 WindowsError:[Error 2]

abaqus提交job总是提示“WindowsError [Error 2”,报这个错误,可能是由于安装其他软件改变了abaqus软件的路径导致,总结了看到的教程,按照下面的方法可以解决这个问题。 步骤一:找到你的abaqus安装路径(我是按照一个安装视频安装的,安装路径为SIMULI1),然后找到SIMULIA文件夹,点击进入后找到commands文件夹,将这个路径复制下来。 步骤二:我的电脑右键属性,在左侧中找到高级系统设置并...

az101za的博客 1万+

关于 MCU 芯片外围电路的快速入门介绍

MCU 外围电路的核心是“围绕 MCU 需求,搭建稳定、匹配的外部支撑”,入门阶段无需掌握复杂设计,只需先吃透供电、复位、时钟、IO 驱动、基础通信这五大模块,再逐步扩展存储、显示、传感器等进阶功能。实践中多调试、多参考成熟方案,是快速掌握外围电路设计的关键。码字不易,若觉得本文对你有用,欢迎,相关技术热点时时看🔥🔥🔥​​​…

JiaWen的博客 1643

算法基础题:木棍切割问题

本文章参考https://blog.youkuaiyun.com/qq_30432997/article/details/85283294 为下列问题设计一个动态规划算法。已知小木棍的销售价格pi和长度i相关,i=1,2,…,n,如何把长度为n的木棍切割为若干根长度为整数的小木棍,使得所获得的总销售价格最大?该算法的时间效率和空间效率各是多少? 长度为n的最大价值 price(n)=MAX(price(i)+...

cometo_bowl的博客 5867

手把手教你用TiggerRamDisk绕过iPhone/iPad激活锁(支持iOS16.3,Win/Mac双平台保姆级教程)

本文详细介绍了如何使用TiggerRamDisk工具绕过iPhone/iPad的激活锁,支持iOS16.3系统,并提供Windows和Mac双平台的保姆级教程。从工具准备、设备连接到核心解锁流程,一步步指导用户完成操作,帮助二手设备或旧设备重获新生。

weixin_29323493的博客 910

(动态规划)1547. 切棍子的最小成本(区间dp)/221. 最大正方形 / 1312. 让字符串成为回文串的最少插入次数(区间dp)

1547. 切棍子的最小成本 题目描述 有一根长度为 n 个单位的木棍,棍上从 0 到 n 标记了若干位置。例如,长度为 6 的棍子可以标记如下: 给你一个整数数组 cuts ,其中 cuts[i] 表示你需要将棍子切开的位置。 你可以按顺序完成切割,也可以根据需要更改切割的顺序。 每次切割的成本都是当前要切割的棍子的长度,切棍子的总成本是历次切割成本的总和。对棍子进行切割将会把一根木棍分成两根较小的木棍(这两根木棍的长度和就是切割前木棍的长度)。请参阅第一个示例以获得更直观的解释。 返回切棍子的 最小总

windyjcy的博客 752

YOLOv8架构革命:通过EfficientViT融合实现精度-速度的帕累托突破

目标检测领域长期存在精度与速度的权衡难题。视觉Transformer(ViT)的引入解决了长距离依赖问题,但其巨大的计算复杂度制约了实时应用。最新研究表明,将轻量级ViT与YOLO架构融合,可在几乎不损失推理速度的前提下,将mAP提升3-8个百分点。这种架构改进方案已在工业检测、自动驾驶、安防监控等多个领域得到验证,在保持实时性的同时显著提升了复杂场景下的检测可靠性。通过模块化设计,可以灵活适配不同规模的YOLOv8模型,为实际应用提供精度-速度的帕累托最优解。

FJN110的博客 148

微信小程序 - 最新详细实现用户保存下载视频到手机相册,将视频临时路径、在线播放地址(网络路径)URL存储到手机,弹出访问手机相册权限询问,支持视频格式mp4、avi、mov、wmv、flv、webm

微信小程序,视频,手机相册,保存,另存为,小程序保存到相册权限,writePhotosAlbum,一键保存视频到手机相册功能(视频来源为链接),第一次要获取用户授权,授权使用相册权限,小程序视频下载,如何把视频下载到相册,下载一个视频到本地相册,显示下载进度,可取消下载,视频下载到本地,微信小程序视频如何下载,保存视频到相机,页面播放视频并下载到本地,安卓系统,苹果ios保存到相册报错,权限拒绝后打不开,添加相册授权弹框拒绝后再也出不来了,实现保存视频到手机相册功能,将mp4在线视频下载并存储到用户的手机中

🏆 前端领域优质创作者 7623

UVA10003[Cutting Sticks] 区间动态规划模型

UVa10003 区间动态规划模型

Venishel的博客 503

计算机等级考试(二级WPS)---真题14套

目录 真题14一、选择题二、WPS文字三、WPS表格四、WPS演示21.打开考生文件夹下的素材文档 “WPS.docx”(.docx 为文件扩展名),后续操作均基于此文件,否则不得分。小周正在整理一份关于极光的文档,请按要求帮助她完成文档的排版工作。1.将全文中的手动换行符全部替换为中文句号并回车,删除文中的空行和空格。2.将正文第 2 段(“在我國的古書…… 極光”)中的繁体字转换成简体字,并为其设置 “正文” 样式。3.对文档样式进行如下设置:4.为 “1.3 极光的形态” 一节中列出的五种极光形态特征

2401_82750246的博客 1169

[动态规划]UVA10003 - Cutting Sticks

题意: 你的任务是替一家叫Analog Cutting Machinery (ACM)的公司切割木棍。切割木棍的成本是根据木棍的长度而定。而且切割木棍的时候每次只切一段。 很显然的,不同切割的顺序会有不同的成本。例如:有一根长10公尺的木棍必须在第2、4、7公尺的地方切割。这个时候就有几种选择了。你可以选择先切2公尺的地方,然后切4公尺的地方,最后切7公尺的地方。这样的选择其成本为:10+8+6=24。因为第一次切时木棍长10公尺,第二次切时木棍长8公尺,第三次切时木棍长6公尺。但是如果你选择先切4公尺的地

九问的烦恼 1723

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

【UVA】10003-Cutting Sticks(动态规划、矩阵链乘)

一到动态规划提,不过似乎ke

花月阁 675

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

uva10003 Cutting Sticks 经典dP,表达式上的动态规划

You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work re

qwesde 1069

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

UVa 10003 Cutting Sticks

 题目是经典DP,和矩阵相乘的最小乘法次数那个是一样的 f[i,j]=min{f[i,k]+f[k,j]}+j-i (k是i,j之间的木棍切割点) f[0,L]就是答案。由于划分阶段貌似比较困难,于是毫不犹豫的使用记忆化搜索开始的时候f数组开了1000*1000(由于L最大为1000),然后转移状态的时候从把所有的切割点过一遍,复杂度是O(kn^2),k于是提交,居然TLE

个人独立博客http://www.acb0y.cn/ 2028

uva 10003Cutting sticks(动态规划水题)

题意:给一根木棍,还有n个切割点,每个切割点的费用为当前切割长度,求最小费用。 #include #include #include #include #include #include #include #include #include #include #include #include #include #define eps 1e-6 #def

GODSPEED 538

UVA - 10003 - Cutting Sticks(动态规划)

点击打开链接 题意:给出一个长度为L的木棍和N个要切的点pt[i],每次切割的代价为切割前木棍的长度,求总代价的最小值。 记忆化搜索:d[x][y] = 区间[x, y]的最小代价。 d[x][y] = min(d[x][y], dp(x, pt[i])+dp(pt[i], y)+(y-x)); 2.179MS…… #include #include #include

NightWind 821

紫书例题9-9 uva10003 动态规划方法2

// UVa10003 Cutting Sticks // // 算法:设d[i][j]为切割小木棍i~j的最优费用,则d[i][j]=min{d[i][k]+d[k][j]}+a[j]-a[i]。最后的a[j]-a[i]是第一刀的费用。然后分成i~k和k~j两部分。 #include<cstdio> #include<cstring> using namespace std; const int maxn = 50 + 5; int n, L, a[maxn], vis[ma.

stuman的专栏 148

UVA - 10003 Cutting Sticks(动态规划)

#include<iostream> #include<cstring> using namespace std; const int maxn = 50 + 3; int l, n; int c[maxn]; int dp[maxn][maxn]; int vis[maxn][maxn]; int solve2(int i, int j) {...

weixin_30648587的博客 118

uva 10003 Cutting Sticks (动态规划:区间DP)

题意是根据从一个木棍中间截取不同长度,qiu

小华在努力~ 515

[中等] UVa OJ 10003 Cutting Sticks 动态规划

题目描述 基本思路: 本题就像是一个逆向的堆石子问题,堆石子是把石子堆起来,而这次是把木棍切开来,但实际上解起来都是一样的。 状态转移方程:d[i][j]=min{d[i][k]+d[k][j]}+a[j]-a[i],i其中d[i][j]表示切割第i个切割点到第j个切割点之间的木棍需要的最小花费,a[i]表示第i个切割点的实际长度,k为i与j之间的切割点。 具体代码: #include

zypang1的博客 325

UVA 10003 Cutting Sticks 区间DP+记忆化搜索

UVA 10003 Cutting Sticks+区间DP 纵有疾风起 题目大意 有一个长为L的木棍,木棍中间有n个切点。每次切割的费用为当前木棍的长度。求切割木棍的最小费用 输入输出 第一行是木棍的长度L,第二行是切割点的个数n,接下来的n行是切割点在木棍上的坐标。 输出切割木棍的最小费用 前话-区间dp简单入门 区间dp的入门下面博客写的非常好,我就是看的他们博客学会的,入...

weixin_30316097的博客 160

uva 10003 Cutting Sticks 【区间dp】

题目:uva 10003 Cutting Sticks 题意:给出一根长度 l 的木棍,要截断从某些点,然后截断的花费是当前木棍的长度,求总的最小花费? 分析:典型的区间dp,其实和石子归并是一样的,花费就是石子的和,那么久不用多说了。 AC代码: #include #include #include #include #include #include #in

大神养成中..... 1324

UVA 10003 Cutting Sticks(区间dp)

题目链接:UVA - 10003 Cutting Sticks题意 给一长度为L的棍子,和n个切割点,每次切割的代价为当前的棍子的长度,问最少的总切割代价是多少。 思路 典型的区间dp dp[i][j] = min(dp[i][k]+dp[k][j]+a[j]-a[i]) |i代码递推#include <iostream> #include <algorithm> #include <

YiShi's Blog 1296
上一篇: uva 674 - Coin Change(动态规划)
下一篇: uva 116 - Unidirectional TSP(精心设计的测试数据)
lzw_java
博客等级 码龄15年 49粉丝 73原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值