北大ACM2485 - Highways(最小生成树)

pku acm 2485 Highways代码 pku acm 2485 Highways代码 最小生成树的prim算法,有详细的注释 立即下载

这是一道非常简单的关于最小生成树的问题。我们通过该题,完成对朴素prim、prim+heap、kruskal算法 的理解。

朴素Prim算法

设共有n个顶点,顶点之间没有必然的顺序,开始将其中一个顶点的权值设为0,其他设为最大(无穷大),花销是o(n)。每次从其中选择一个未处理过的权值最小的顶点,花销是O(n);然后更新和该顶点相连的顶点的权值,花销是o(n);共需要进行n次,花销是o(n),以上三个步骤是嵌套关系,所以花销是o(n3)。所以总花销是o(n)+o(n3)=o(n3)。

prim处理的对象是顶点,所以,数据结构是struct vertex。

运行结果是 760K 172MS。
代码如下:
/*
 *
 * Introduction : ACM of pku
 * ID : 2485
 * alg : MST.Prim
 * Author : Gykimo
 * Date : 20130115
 * 
 */

#include <stdlib.h>
#include <stdio.h>
#include <queue>

using namespace std;

struct vertex
{
	int minDist;	//the min distance to the adjcent nodes
	bool inMST;	//is walked
};

int case_num = 0;
int village_num = 0;

int edge[500][500];
vertex* vertices = NULL;

int max_lenth = 0;

void init(){
	vertices = (vertex*)malloc(village_num * sizeof(vertex));
	
	for(int i=1; i<village_num; i++){
		vertices[i].minDist = 65536;
		vertices[i].inMST = false;
	}

	vertices[0].minDist = 0;
	vertices[0].inMST = false;
}

/*获得未处理的权值最小的顶点*/
int getVertexOfMinDist(){
	int min = 65536;
	int minIndex = -1;
	for(int i=0; i<village_num; i++){
		if(!vertices[i].inMST && vertices[i].minDist < min){
			min = vertices[i].minDist;
			minIndex = i;
		}
	}
	return minIndex;
}

/*更新和index顶点相邻的顶点的权值*/
void updateMinDist(int index){
	for(int i=0; i<village_num; i++){
		if(!vertices[i].inMST && (vertices[i].minDist > edge[index][i])){
			vertices[i].minDist = edge[index][i];
		}
	}
}

void prim(){
	vertex* v = NULL;
	int minIndex = 0;

	while((minIndex = getVertexOfMinDist()) >= 0){
		v = vertices + minIndex;
		v->inMST = true;
		
		if(max_lenth < vertices[minIndex].minDist){
			max_lenth = vertices[minIndex].minDist;
		}

		updateMinDist(minIndex);
	}

	printf("%d\n", max_lenth);
}

void readLine(){
	scanf("%d", &case_num);
	for(int i=0; i<case_num; i++){
		scanf("%d", &village_num);
		for(int j=0; j<village_num; j++){
			for(int k=0; k<village_num; k++){
				scanf("%d", &edge[j][k]);
			}
		}

		init();
		prim();
		max_lenth = 0;
		free(vertices);
	}
}

int main(){
	readLine();
	return 0;
}

Prim + heap算法


Kruskal算法

由于Kruskal算法是对边进行处理的一个算法,而边除了有边的权值之外,还需要边的两个端点,所以共定义了两个数据结构
class edge和class vertex。

运行结果:8504K 516MS

注意:
如果将函数deinit()中注释掉的代码放开的话,运行结果是超时。

/*
 *
 * Introduction : ACM of pku
 * ID : 2485
 * alg : MST.Kruskal
 * Author : Gykimo
 * Date : 20130115
 * 
 */

#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

class vertex
{
	public:
		vertex(){
			make_set();
		}
		
		vertex * find_set(){
			if(mParent != this){
				mParent = mParent->find_set();
			}
			
			return mParent;
		}

		void union_set(vertex * v){
			link(v->find_set());
		}
		
	private:
		vertex * mParent;
		int mRank;

		void make_set(){
			mParent = this;
			mRank = 0;
		}
		
		void link(vertex * v){
			if(mRank < v->mRank){
				mParent = v->find_set();
			}else{
				v->mParent = this;
				if(mRank = v->mRank){
					mRank++;
				}
			}
		}
};

class edge
{
	public:
		edge(vertex& u, vertex& v, int w){
			v1 = &u;
			v2 = &v;
			weight = w;
		}

		bool kruskal_check(){
			if(v1->find_set() != v2->find_set()){
				add_to_mst();
				return true;
			}
			return false;
		}

		int weight;

	private:
		vertex * v1;
		vertex * v2;
		
		void add_to_mst(){
			v1->union_set(v2);
		}
};

int case_num = 0;
int village_num = 0;
vector<edge*> edges;
vertex * vertices;
int max_lenth = 0;

void init(){
	vertices = new vertex[village_num];
}

void deinit(){
	delete [] vertices;
	/*
	for(vector<edge*>::iterator iter=edges.begin(); iter !=edges.end(); ++iter){
		delete (*iter);
	}*/
	edges.clear();
}

bool cmp(edge* e1, edge* e2){
	if(e1->weight < e2->weight)
		return true;
	return false;
}

void kruskal(){
	int loop_num = village_num;
	sort(edges.begin(), edges.end(), cmp);

	for(vector<edge*>::iterator iter=edges.begin(); iter !=edges.end(); ++iter){
		if((*iter)->kruskal_check()){
			loop_num--;
			max_lenth = (*iter)->weight;
		}
		if(loop_num == 0)
			break;
	}

	printf("%d\n", max_lenth);
}

void readLine(){
	int tmp;
	edge* e;
	
	scanf("%d", &case_num);
	for(int i=0; i<case_num; i++){
		scanf("%d", &village_num);
		init();
		
		for(int j=0; j<village_num; j++){
			for(int k=0; k<village_num; k++){
				scanf("%d", &tmp);
				if(k>j){
					e = new edge(vertices[j], vertices[k], tmp);
					edges.push_back(e);
				}
			}
		}
		kruskal();
		deinit();
	}
}

int main(){
	readLine();
	return 0;
}

结论



poj 2485 Highways 测试数据 poj 2485 Highways 测试数据 解题报告:http://blog.youkuaiyun.com/qq7366020/article/details/8615293 立即下载

相关推荐

POJ2485-Highways【Prim】

北大POJ2485-Highways【Prim】 解题报告+AC代码

Highways(p1751)

感受:搞了好久好久, 关键:最小生成树的路径, #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; double map[1000][1000]; struct my { dou

jiangjiashi的博客 787

MySQL8.2.0下载安装

4、点击No thanks,just start my download,就是只是开始下载的意思,点击下载,等待下载完成。5、新建空白行,或直接双击紧挨的空白行,把复制的mysql的安装路径bin路径复制粘贴过来,确定,确定,确定。1、上面点击finish后,自动勾选了run mysql配置,自动会打开配置页面,点击Next。1、双击安装包,进入安装流程,勾选我同意 I accept,next。2、根据自己需要选择,我选的第二个,可以自己改安装路径。2、默认,点击Next,记住默认端口3306。

m0_59681797的博客 1万+

Highways

The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has already constructed a number of highways connecting some of the most important tow

qq_52898168的博客 177

Vast.ai GPU服务器租用与SSH密钥连接实战指南

本文详细介绍了如何在Vast.ai平台租用GPU服务器并通过SSH密钥安全连接的全流程。从注册、选配GPU型号到SSH密钥生成与配置,再到实战中的端口转发和文件传输技巧,帮助用户高效利用云端GPU资源进行深度学习等计算密集型任务。

weixin_29574585的博客 527

解决rt-thread上使用SPI+DMA

首先阐述下遇到的问题 使用SPI读取icm20602数据,读取频率为1000hz,使用stm32f407主控,发现CPU占用率达到了70%,将此线程注释掉后CPU占用率掉到25%,看来这里要着重优化,便萌生了使用DMA的想法。 使用SPI+DMA要进行的配置 1.开启RTT设备驱动。点击自己的工程 ->RT-Thread Setting2.在board.hzhong3.在board.c文件里加入以下函数,此函数受设备框架调用 void HAL_SPI_MspInit(SPI_HandleTypeDef

响望的博客 8085

ACM-最小生成树之Highways——poj2485

ACM 最小生成树 Highways poj2485 Prim

继续激情,继续奋斗。 2647

06-esp32-idf开发调试方法(内置JTAG,OpenOCD调试)

使用VS Code和ESP-IDF进行ESP32开发和调试 在我们搭建 **IDF** 框架后,**OpenOCD** 已经自动下载好了, 我们通过 **JTAG** 接口连接使用 **OpenOCD** 进行调试。而**ESP32**芯片中内置 了**JTAG** 电路,无需额外芯片即可调试,更加方便,所以这里我们讲解使用模块自带的usb-jtag接口进行调试。

宁子希的博客 1万+

POJ 2485 Highways(prim算法)

Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13404   Accepted: 6237 Description The isl

qiyazhuang的专栏 641

69、SAP数据库归档重做日志备份策略与工具详解

本文详细解析了SAP数据库归档重做日志备份的重要性及策略,介绍了SAP提供的备份工具brarchive及其配置和使用方法,探讨了BRBACKUP与BRARCHIVE的联合运行、一致在线备份、备用数据库备份场景以及备份策略的综合应用与优化。此外,还分析了备份过程中常见问题的解决方法、备份监控与评估流程、与第三方备份解决方案的集成方式,以及未来备份技术的发展趋势和应对策略。通过合理运用这些策略和工具,可以有效保障SAP数据库的安全性和可恢复性。

peace的博客 135

PyTorch 最新安装教程(2021-07-27)

PyTorch 最新安装教程(2021-07-27)前言1. 安装 Anaconda2. 检查显卡,更新驱动3. 创建PyTorch环境4. 配置清华TUNA镜像源5. 安装 PyTorch6. 测试 前言 万事开头难! 这句话又一次被我验证。 记得前不久刚陷入Tensorflow2.0的安装困境,这一次又被PyTorch 搞哭辽。 孩子太难了o(╥﹏╥)o,不过还好最终成功安装,感谢全网资源,感谢大佬们的博客!被我一次一次试了出来。 1. 安装 Anaconda Anaconda 是一个用于科学计算的 P

全网粉丝30W+,优快云、稀土掘金人工智能领域签约作者,人工智能、大模型、Python 爬虫,商务合作,请私信沟通。 23万+

[ACM] poj 2485 Highways (最小生成树)

Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21056   Accepted: 9723 Description The island nation of Flatopia is perfectly flat. Unfortunately,

逆风的方向 更适合飞翔 2545

Intellij IDEA 使用教程(一)Jdk安装和配置

一.JDK下载 这里下载的是Java SE 8u181 64位版本。可以根据自己电脑配置来选择不同版本。 官网下载JDK 二.安装JDK 双击运行jdk-8u181-windows-x64.exe安装程序 选择安装目录,然后点击下一步 等待安装 安装JRE,就是java的运行环境,可以安装在java目录下 等待安装 安装完成。点击关闭。 三.java环境变量配置 关于环境变量的配置,...

岁月不饶人,我亦未曾饶过岁月 4053

POJ 2485--Highways

题目: Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of

Time_Life的专栏 428

lwip-2.0.3

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

深度学习工具包 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")

POJ2485-Highways

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 提示:题意很简单,就是求最小生成树的最大边。继续Prim吧O(∩_∩)O //Memory T...

ζёСяêτ - 小優YoU 6619

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

poj 2485 Highways prim最小生成树 基础 球最小生成树中得最大边

prim基础!! 球最小生成树中得最大边#include #include using namespace std; int map[505][505],dis[505],vis[505],a[505]; int sum[505],m; int cou; bool cmp(int x,int y) { return x>y; } void prim(int k) { i

代码随想录 1455

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

最小生成树

常用的有三种方法 相关代码,请参考《北大ACM2485 - Highways(最小生成树)》 朴素Prim算法 Prim算法思路 从任意一个顶点(它就是最后生成树的根结点)开始,首先设置和它相邻顶点的权值(指该顶点和相邻顶点已知长度最小边的长度;初始值是无穷大),然后将所有未加入生成树顶点中权值最小的顶点加入到生成树中,然后更新新加入生成树顶点相邻顶点的权值;依次执行,直到所有顶点

等等... 大雄,有啦! 1042

POJ - 1751 Highways (最小生成树 Kruskal、Prim)

                                            Highways Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian gov...

K.X的博客 1070

POJ 2485 : 最小生成树(kruskal+并查集)

Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it w

cesc 2455

图论trainning-part-1 F. Highways

F. Highways Time Limit: 1000ms Memory Limit: 10000KB 64-bit integer IO format:%lld Java class name:Main The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia ...

weixin_30439131的博客 373

北大 ACM highways问题研究(最小生成树)

#include<stdlib.h> #include<stdio.h> #include<queue> struct vertex//代表一个村庄 { int minDist;//到相邻结点的最小的距离 bool inMST;//这个村庄是否已经被走过 }; int case_num=0;//用例数 ...

deng0004的博客 187

ACM各题型OJ题目总结 POJ、ZOJ、HDU

本帖题目类型: 目录 1、递归与分治(27) 2、动态规划类问题(189题) 3、贪心算法类问题(79) 4、回溯算法(36) 5、图的搜索(98) 6、图论(85) 7、数论(117) 8、组合数学(99) 9:、分支限界算法(14) 推荐网站:https://vjudge.net/ 下面给出各题型的部分例题。 注:1.题目来源于ZOJ,POJ和HUD; ...

一定要站在自己热爱的生活里闪闪发光 4万+

[ACM_图论] Highways (变形说法的最小生成树)

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28972#problem/C 题目给出T种情况,每种情况有n个城镇,接下来每一行是第i个城镇到所有城镇的距离(其实就是个可达矩阵)。 求建设一条公路联通所有城镇并且要求最长的一段最小(其实就是最小生成树)!代码如下: View ...

weixin_34409741的博客 153

HDUOJ Highways (最小生成树)

Highways Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 18   Accepted Submission(s) : 6 Problem Description The island nation of Flatopia

君只见独不见的专栏 423

北大ACM1163 - The Triangle (枚举法&备忘录法&动态规划)

1.1.1           枚举法 该问题我使用了枚举法、备忘录法、动态规划法主要是对三种算法进行比较。 任何选择的问题,都可以通过穷举所有可能性,然后从中选择适合的项,这就是枚举法。枚举法是自顶向下,一般也会有递归公式。 设h为Triangle 的高度,v[i,j]为点(i,j)的数字值,sum[i,j]表示到从底到点(i,j)的所有路径中的最大和 运行结果 Time Limi

等等... 大雄,有啦! 2357
上一篇: C++ - 回调函数
下一篇: 说明
G机器猫
博客等级 码龄16年 106粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值