uva10308 - Roads in the North 树形DP

uva1451 - Average 单调队列维护下凸曲线 A DNA sequence consists of four letters, A, C, G, and T. The GC-ratio of a DNA sequence is the number of Cs and Gs of the sequence divided by the length of the sequence. GC-ratio is important in gene 阅读详情

Problem I

Roads in the North

Input: standardinput

Output: standardoutput

Time Limit: 2seconds

Memory Limit: 32MB

 

Building and maintaining roadsamong communities in the far North is an expensive business. With this in mind,the roads are built in such a way that there is only one route from a villageto a village that does not pass through some other village twice.

Given is an area in the far North comprising anumber of villages and roads among them such that any village can be reached byroad from any other village. Your job is to find the road distance between thetwo most remote villages in the area.

The area has up to 10,000 villages connected by road segments. The villages arenumbered from1.

Input

The input contains several sets of input. Eachset of input is a sequence of lines, each containing three positive integers:the number of a village, the number of a different village, and the length ofthe road segment connecting the villages in kilometers. All road segments aretwo-way. Two consecutive sets are separated by a blank line.

Output

For each set of input, you are to output a singleline containing a single integer: the road distance between the two most remotevillages in the area.

Sample Input

5 1 6
1 4 5
6 3 9
2 6 8
6 1 7

Sample Output

22

  第一次做树形DP,感觉就是在树上做一般的DP,在树上找关系。

  这道题是没有环的,也就是一个地方到另一个地方只有一种走法。要在图上找两个点,使他们之间的距离最长。

  那么两个点一定都是叶子节点(如果不是叶子节点,那么一定还可以延伸),这两个点连接的路径中经过的点都是他们的父节点,包括他们自己。

  只要遍历每个点,把这个点当做父节点,找到他子树中最长的一条路径和次长的一条路径加起来就是以这个点为父节点的最长路径。

  随时更新最大值就行了。

 DP 既然在树上,那就需要节点和节点之间的连接关系,所以应该都会用到vector,如果有多个参数,可以写个结构体,vector<结构体名>a[N],两个参数可以用pair,vector容器的push_back(t)是在容器的最后添加一个值为t的数据,还有push_front()是在前面加。一开始要先clear(),另外还有empty()之类的很多。。到时用到再看吧=。=

  当然也可以不用vector,自己写个连接表也行。

  代码:

  用vector的

#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int> pii;
vector<pii> a[10010];
char str[100];
int ans,dp[10010][2],vis[10010];

void add(int u,int v,int w){
    pii t;
    t.first=v;
    t.second=w;
    a[u].push_back(t);
    t.first=u;
    a[v].push_back(t);
}
void DFS(int r){
    vis[r]=1;
    int i,v,w;
    pii t;
    dp[r][0]=dp[r][1]=0;
    for(i=0;i<a[r].size();i++){
        t=a[r][i];
        v=t.first;
        w=t.second;
        if(!vis[v]){
            DFS(v);
            if(dp[v][0]+w>dp[r][0]){
                dp[r][1]=dp[r][0];
                dp[r][0]=dp[v][0]+w;
            }
            else if(dp[v][0]+w>dp[r][1]) dp[r][1]=dp[v][0]+w;
        }
    }
    if(dp[r][0]+dp[r][1]>ans) ans=dp[r][0]+dp[r][1];
}
int main(){
    freopen("in.txt","r",stdin);
    while(gets(str)){
        int u,v,w,i;
        for(i=0;i<10010;i++) a[i].clear();
        while(str[0]){
            sscanf(str,"%d%d%d",&u,&v,&w);
            add(u,v,w);
            if(!gets(str)) break;
        }
        ans=0;
        memset(vis,0,sizeof(vis));
        DFS(1);
        printf("%d\n",ans);
    }
    return 0;
}

 连接表的

 

#include<cstring>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std;
char str[100];
int ans,e,dp[10010][2],vis[10010],edge[1000000][2],head[10010],next[10010];
void add(int u,int v,int w){
    edge[++e][0]=v;
    edge[e][1]=w;
    next[e]=head[u];
    head[u]=e;
    edge[++e][0]=u;
    edge[e][1]=w;
    next[e]=head[v];
    head[v]=e;
}

void DFS(int r){
    vis[r]=1;
    int i,v,w;
    dp[r][0]=dp[r][1]=0;
    for(i=head[r];i;i=next[i]){
        v=edge[i][0];
        w=edge[i][1];
        if(!vis[v]){
            DFS(v);
            if(dp[v][0]+w>dp[r][0]){
                dp[r][1]=dp[r][0];
                dp[r][0]=dp[v][0]+w;
            }
            else if(dp[v][0]+w>dp[r][1]) dp[r][1]=dp[v][0]+w;
        }
    }
    if(dp[r][0]+dp[r][1]>ans) ans=dp[r][0]+dp[r][1];
}
int main(){
    freopen("in.txt","r",stdin);
    while(gets(str)){
        int u,v,w,i;
        e=0;
        memset(head,0,sizeof(head));
        memset(next,0,sizeof(next));
        while(str[0]){
            sscanf(str,"%d%d%d",&u,&v,&w);
            add(u,v,w);
            if(!gets(str)) break;
        }
        ans=0;
        memset(vis,0,sizeof(vis));
        DFS(1);
        printf("%d\n",ans);
    }
    return 0;
}



uva10237 - Bishops 互不攻击的象 Problem B Bishops Input: standard input Output: standard output Time Limit: 4 seconds Memory Limit: 32 MB   A bishop is a piece used in thegame of chess which is played on a board of squa 阅读详情

相关推荐

STM32G474多通道ADC电压采集:软件触发与单次转换实战

本文详细介绍了STM32G474多通道ADC电压采集的实战方法,重点讲解了软件触发与单次转换的实现技巧。通过硬件设计、HAL库配置、多通道轮询采集及数据处理等环节的详细解析,帮助开发者高效完成精确电压采集任务。文章还提供了常见问题调试技巧和性能优化建议,适用于需要高精度电压监测的嵌入式应用场景。

weixin_28720767的博客 471

uva 10308 - Roads in the North(dfs)

题目链接:uva 10308 - Roads in the North 题目大意:给出一个无环无向图,求任意两点间的最大距离。输入空行问该组测试输入结束。 解题思路:输入比较恶心,因为这个WA了一次,这题可以用dfs去做,任意选一个节点作为根节点,然后遍历与它相连的所有点,维护最大值就可以了,因为任意两点可以看成是以父亲节点而相连的。 #include #inc

不慌不忙、不急不躁 1795

【报错】sqli-labs靶场搭建出现“Unable to connect to the database: security”

搭建sqli-labs靶场时,“Unable to connect to the database: security”报错解决

九芒星的博客 3007

Roads in the North - UVa 10308 树形dp

Problem I Roads in the North Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB   Building and maintaining roads among communities in the far North is an ex

提比的强行AC 787

第4课 SiC MOSFET的动态特性——关断过程

本文分析了SiC MOSFET的关断过程,将其划分为四个阶段:栅源电容放电阶段(t6-t7)、米勒平台阶段(t7-t8)、电压过冲阶段(t8-t9)和换流结束阶段(t9-t10)。通过等效电路详细描述了各阶段的电压电流变化特点。同时探讨了MOSFET的极间电容特性,包括输入电容Ciss、输出电容Coss和反向转移电容Crss,分析了它们对器件开关速度、损耗及电压变化速率的影响。研究指出这些非线性电容会显著影响器件的动态性能。

嵌入式老牛的博客 1056

超简单的视频换脸,效果相当不错!完全白嫖的技术,来自ComfyUI 官方客户端一键搞定!手把手教会你如何下载安装部署,而且教你如何使用。

如果你电脑上没有安装Visual Studio的C++桌面开发组件,还有Windows应用SDK C++模板,那么你需要自行去下载安装下【安装后默认界面会自动识别系统语言,当然如果你是中文繁体用户,那么你可以在 ComfyUI 的管理器里下载。】并把它放入根目录-models-insightface文件夹内 , 同时下载视频换脸工作流 【分享手把手教你视频换脸,本地部署,轻轻松松当上“电影主角”】,否则insightface无法被正常载入。) 这是换脸必备的工具 ,安装后重启;

TianLeung的博客 2957

UVA10308Roads in the North(dfs)

UVA10308Roads in the North(dfs) 题目链接 题目大意:给你多条道路,每条道路都连着两个不同的城市,并且给你这条路的距离,现在要求你找出离得最远的两个城市之间的距离。 解题思路:一开始,想用dfs,可是没有想到只需要任意找个节点dfs一次就可以了,还想着如果每个点都找一次,那么肯定行不通。看了题解后才发现只需要找一次就可以了,因为题目给的是一棵树,而且

785

告别Keil/IAR:在VSCode中用CMake+Clangd打造丝滑的STM32开发环境(附完整配置)

本文详细介绍了如何在VSCode中使用CMake和Clangd搭建高效的STM32开发环境,替代传统的Keil/IAR工具。通过完整的配置指南和快速开发技巧,帮助开发者实现轻量级、高度可定制的现代化开发流程,显著提升STM32项目的开发效率。

weixin_26843605的博客 168

UVA - 10308 Roads in the North

题意:在一棵二叉树里找最远的两个点的距离,题目的输入和树的构建的看了好久,每次将一个节点加进树里,DFS一次就可以了,因为他是二叉树,所以只要一次 #include #include #include using namespace std; const int MAXN = 10100; long long ans = 0; int p[MAXN],next[MAXN]; int

那些年 1308

时间序列预测 | Python实现ARIMAX和VARMAX时间序列数据预测

时间序列预测 | Python实现ARIMAX和VARMAX时间序列数据预测 目录时间序列预测 | Python实现ARIMAX和VARMAX时间序列数据预测基本介绍ARIMAXVARVARMAVARMAXSESHWES参考资料 基本介绍 本文介绍ARIMAX、VAR、VARMA和VARMAX基本概念及其Python程序设计。 ARIMAX 具有外源回归量的自回归整合移动平均值(ARIMAX)是 ARIMA 模型的扩展,其还包括外生变量的建模。 外生变量也称为协变量,可以被认为是并行输入序列,其在与

前程算法屋的博客 6693

【图像拼接】源码精读:Parallax-Tolerant Unsupervised Deep Image Stitching(UDIS++)

注:Pytorch代码。【图像拼接论文精读】专栏对应文章【图像拼接】论文精读:Parallax-Tolerant Unsupervised Deep Image Stitching(UDIS++)配合对应的文章阅读,效果更佳!注:请重点关注代码段中的注释!!!有一些讲解的东西直接写在代码段的注释中了,同时多关注红色字体和绿色字体!!!我认为深度学习方法和传统方法有很多相似之处。比如:深度学习中的损失函数和传统方法中的对齐项、失真项等其实原理相同,只是求解方式不同。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 7288

UVA10308

struct Line{ double _left ; double _right ; Line(){} Line(double l , double r):_left(l) , _right(r){} friend bool operator < (const Line& a , const Line& b){

老李2009 495

BoT-SORT实战:手把手教你实现BoT-SORT训练和测试

文章目录摘要1、数据准备2、配置BoT-SORT环境2.1、获取代码2.2、创建虚拟环境2.3、安装必要的包2.3.1、安装pytorch2.3.2、安装cython2.3.3、安装Cython-bbox2.3.4、安装faiss2.3.5、安装其他的包3、训练3.1、生成REID数据集3.2、预训练模型3.2.1、ByteTrack预训练模型3.2.2、REID预训练模型3.3、开始训练4、如何更改FASTREID的BackBone?5、测试5.1、测试视频5.2、测试摄像头5.3、多类别测试 摘要 Bo

m0_47867638的博客 2308

UVa 10308 Roads in the North 树的直径

题目来源:UVa 10308 Roads in the North 题意:求距离最远的2点之间的距离 思路:裸的树的直径 或者树形DP #include #include #include using namespace std; const int maxn = 100010; struct node { int to, w; node(){} node(int to, int

嗯。 994

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

uva 10308 Roads in the North

树型DP 这题刘汝佳居然归在数学题里面,他的用意应该是想归在递推的,但是这题更应该属于一个经典树DP 题意:给一个图,两个点间不会有重边,边时双向连通的,另外注意这句话, there is only one route from a village to a village that does not pass through some other village twice. 这句话说明...

weixin_33895016的博客 89

老版QQ原生表情gif动态

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

UVA10308 Roads in the North 题解(博客搬家)

因为从一个村庄到另一个村庄时,同一个的村庄不会经过两次,所以村庄和路其实就是一棵无根树,用dfsdfsdfs 找到结点 aaa 的子结点到 aaa 的最大距离再加上次大距离即可。找到的数的值就是树的直径。 也可以先从任意点 aaa 一遍 bfsbfsbfs 找到离当前点最远的点 bbb,再从该点再 bfsbfsbfs 一遍找到离该点最远的点 ccc。点 bbb 到点 ccc 之间的距离即为所求。 (其实两种方法都是求树的直径) 就是输入格式真的毒瘤,在输入上调了好久。 代码: 1.dfs 做法 #inclu

cbw3402271334a的博客 262

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

uva 10308 Roads in the North 北方的道路

uva 10308

@fei 3244

uva 10308(无根树变有根)

题意:给出一些村庄之间的路的距离,每个村庄可以到达任意其他村庄,且所有路中不会有环。问任意两个村庄可达的总路径最长是多少。 题解:因为从一个村庄到另一个村庄同一个的村庄不会经过两次,所以村庄和路其实是一棵无根树,用dfs(int a)计算结点a的子结点到a的最大距离,结果就是a的子结点到结点a的最大距离加次大距离。 #include #include #include using n

俯瞰风景 855

uva 10308 (二叉树深搜)

题意: 给点与点间的距离,且点与点间只有一条边,求最长的两点间距离。 代码: #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long using namesp

渐近自由 494

UVA - 10308 - Roads in the North (DFS)

题目传送:UVA - 10308 思路:就是树的遍历,DFS即可,注意输入 AC代码: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #defi

Never say never 829

UVa:10308 Roads in the North

这个题真的是胡乱想了个算法,然后WA了好多次,最后我找到了一组没过的数据,改了之后就AC了。。 图是一个无向无环图,其实就是一棵树。 百度到的题解用了dfs,递归每棵子树,答案可能是某两棵子树的和,最后返回一棵最长的子树。 我的思路类似于拓扑排序或者关键路径,其实原理都是一样的。从度为1的节点开始拓展,不断拓展出更长的路径。 #include #include #include

Fighting 692

UVA10308 Roads in the North

题面传送门 这道题是树的直径裸题。 显然跑两遍dfsdfsdfs找树的直径即可。 但是输入很毒瘤。 所以要信仰stringstreamstringstreamstringstream啊 代码实现: #include<bits/stdc++.h> using namespace std; int n,m,k,x,y,z,ans,tot,pus,flag,maxn,maxs,flags; struct yyy {int to,w,z;}; struct ljb { int head,h[10003

fxt275307894a的博客 201

UVa 10308 Roads in the North (树上的最长路)

10308 - Roads in the North Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1249 思路:由于是一棵树,我们只要随便指定一个树根就开

AC,∑ndless 1715

UVA - 10308 Roads in the North 树的最长距离

题目大意:有N个村庄,有的村庄之间有一条通道连接,并规定,从一个村庄到达另一个村庄的通道不会经过另一个村庄,求经过通道,两个村庄之间的最长距离 解题思路:从一个村庄到达另一个村庄的通道不会经过另一个村庄,这就说明了,这些通道连接起来的村庄是不会构成环路的,所以这是一棵树,问题就转换成了求树的节点之间的最长距离 #include #include #define maxn 20010 int v

静静地码 889

求区间这种数的个数,这个数恰好等于k个互不相等的2的整数次幂之和 数位统计

Description 给定一个区间[x,y],求这个区间中满足下列条件的整数的个数:这个数恰好等于k个互不相等的2的整数次幂之和。例如x=15,y=20,k=2.则有且仅有下列三个数满足题意: 17=2^4+2^0; 18=2^4+2^1; 20=2^4+2^2;   (a^b代表是a的b次方) Input 接下来输入T行,每行对应一个样例,每行有3个整数x, y

1613

数位DP的记忆化搜索形式

数位DP的记忆化搜索形式比一般递推形式好写多了,而且一般不容易出错。   dfs求[0,n]有多少个符合的,先把n换成字符串形式。   cur:现在处理到哪一位。   s:搜索到目前为止,之前的状态,具体什么状态看情况而定。   e:是否到达边界,如果没到这一位只取到9,否则只能取到bit[cur]。   z:前导0标记,也就是是否前面的都是0,有些情况需要特殊判断。   一般情况

1386
上一篇: uva10673 - Play with Floor and Ceil 扩展欧几里德算法
下一篇: uva11181 - Probability|Given 条件概率
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值