Genghis Khan the Conqueror HDU - 4126(MST)

树形dp+MST-hdu-4126-Genghis Khan the Conqueror 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4126 题目意思: 给一图,n个点,m条边,每条边有个花费,给出q条可疑的边,每条边有新的花费,每条可疑的边出现的概率相同,求不能经过原来可疑边(可以经过可疑边新的花费构建的边),注意每次只出现一条可疑的边,n个点相互连通的最小花费的期望。 解题思路: 树形dp+MST。 先用krus 阅读详情

Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元太祖), was the founder of the Mongol Empire and the greatest conqueror in Chinese history. After uniting many of the nomadic tribes on the Mongolian steppe, Genghis Khan founded a strong cavalry equipped by irony discipline, sabers and powder, and he became to the most fearsome conqueror in the history. He stretched the empire that resulted in the conquest of most of Eurasia. The following figure (origin: Wikipedia) shows the territory of Mongol Empire at that time.

Our story is about Jebei Noyan(哲别), who was one of the most famous generals in Genghis Khan’s cavalry. Once his led the advance troop to invade a country named Pushtuar. The knights rolled up all the cities in Pushtuar rapidly. As Jebei Noyan’s advance troop did not have enough soldiers, the conquest was temporary and vulnerable and he was waiting for the Genghis Khan’s reinforce. At the meantime, Jebei Noyan needed to set up many guarders on the road of the country in order to guarantee that his troop in each city can send and receive messages safely and promptly through those roads.

There were N cities in Pushtuar and there were bidirectional roads connecting cities. If Jebei set up guarders on a road, it was totally safe to deliver messages between the two cities connected by the road. However setting up guarders on different road took different cost based on the distance, road condition and the residual armed power nearby. Jebei had known the cost of setting up guarders on each road. He wanted to guarantee that each two cities can safely deliver messages either directly or indirectly and the total cost was minimal.

Things will always get a little bit harder. As a sophisticated general, Jebei predicted that there would be one uprising happening in the country sooner or later which might increase the cost (setting up guarders) on exactly ONE road. Nevertheless he did not know which road would be affected, but only got the information of some suspicious road cost changes. We assumed that the probability of each suspicious case was the same. Since that after the uprising happened, the plan of guarder setting should be rearranged to achieve the minimal cost, Jebei Noyan wanted to know the new expected minimal total cost immediately based on current information.
Input
There are no more than 20 test cases in the input.
For each test case, the first line contains two integers N and M (1<=N<=3000, 0<=M<=N×N), demonstrating the number of cities and roads in Pushtuar. Cities are numbered from 0 to N-1. In the each of the following M lines, there are three integers x i, y i and c i(c i<=10 7), showing that there is a bidirectional road between x i and y i, while the cost of setting up guarders on this road is c i. We guarantee that the graph is connected. The total cost of the graph is less or equal to 10 9.

The next line contains an integer Q (1<=Q<=10000) representing the number of suspicious road cost changes. In the following Q lines, each line contains three integers X i, Y i and C i showing that the cost of road (X i, Y i) may change to C i (C i<=10 7). We guarantee that the road always exists and C i is larger than the original cost (we guarantee that there is at most one road connecting two cities directly). Please note that the probability of each suspicious road cost change is the same.
Output
For each test case, output a real number demonstrating the expected minimal total cost. The result should be rounded to 4 digits after decimal point.
Sample Input
3 3
0 1 3
0 2 2
1 2 5
3
0 2 3
1 2 6
0 1 6
0 0
Sample Output
6.0000

Hint
The initial minimal cost is 5 by connecting city 0 to 1 and city 0 to 2. In the first suspicious case, the minimal total cost is increased to 6;
the second case remains 5; the third case is increased to 7. As the result, the expected cost is (5+6+7)/3 = 6.

不断向大牛学习

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#define INF 0x3f3f3f3f
#define N 3003
using namespace std;
int pre[N];
int dis[N][N];
bool vis[N][N];
int dp[N][N];
struct edge
{
    int a,b;
    int w;
}e[N*N];
int n,m;
int cmp(edge e1,edge e2)
{
    return e1.w<e2.w;
}
vector<int> graph[N];
void init()
{
    for(int i=0;i<n;i++)
        pre[i]=i;
    for(int i=0;i<n;i++)
        graph[i].clear();
    memset(dp,INF,sizeof(dp));
    memset(dis,INF,sizeof(dis));
    memset(vis,false,sizeof(vis));
}
int findd(int x)
{
    //cout<<x<<" "<<pre[x]<<endl;
    return pre[x]==x?x:pre[x]=findd(pre[x]);
}
int prime()
{
    int aa,bb;
    int ans=0;
    int total=n;
    for(int i=0;i<m;i++)
    {
        aa=findd(e[i].a);
        bb=findd(e[i].b);

        if(aa!=bb)
        {
            total--;
            pre[aa]=bb;
            ans+=e[i].w;
            //cout<<ans<<endl;
            vis[e[i].a][e[i].b]=vis[e[i].b][e[i].a]=true;
            graph[e[i].a].push_back(e[i].b);
            graph[e[i].b].push_back(e[i].a);
        }
        if(total==1)
            break;
    }
    return ans;
}
int DFS(int pos,int now,int last)
{
    int ans=INF;
    int v;
    int mn;
    for(int i=0;i<graph[now].size();i++)
    {
        v=graph[now][i];
        if(v==last)
            continue;
        mn=DFS(pos,v,now);
        dp[v][now]=dp[now][v]=min(dp[now][v],mn);
        ans=min(ans,mn);
    }
    if(last!=pos)
        ans=min(dis[pos][now],ans);
    return ans;
}
int main()
{
    int a,b,w;
    int q;
    for(;;)
    {
        scanf("%d%d",&n,&m);
        if(!n&&!m)break;
        init();
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&a,&b,&w);
            dis[a][b]=dis[b][a]=w;
            e[i].a=a;
            e[i].b=b;
            e[i].w=w;
        }
        sort(e,e+m,cmp);
        int ori=prime();
        for(int i=0;i<n;i++)
            DFS(i,i,-1);
            //cout<<ori;
        scanf("%d",&q);
        long long sum=0;
        int countt=q;
        while(q--)
        {
            scanf("%d%d%d",&a,&b,&w);
            if(!vis[a][b])
                sum+=ori;
            else
            {
                int minn=min(dp[a][b],w);
                sum+=ori-dis[a][b]+minn;
            }
        }
        printf("%.4lf\n",(double)sum/countt);
    }
    return 0;
}
React项目实战:用AntV G6打造可折叠组织架构图(附完整代码) 本文详细介绍了如何在React项目中使用AntV G6库构建一个功能完整的可折叠组织架构图。通过实战代码演示了从环境搭建、自定义节点、折叠状态管理到性能优化的全流程,重点解决了企业级应用中处理复杂树形数据、实现流畅交互等核心问题,并提供了可直接复用的组件代码。 阅读详情

相关推荐

Docker+vLLM内网离线部署Qwen3 流程

本文介绍了在CentOS 7系统下进行VLLM容器化部署Qwen3-32B大模型的内网离线方案。首先需准备Nvidia显卡驱动、CUDA 12.4和Docker环境。通过联网机器拉取vllm/vllm-openai镜像并导入内网服务器,同时从魔塔社区下载模型文件。部署时使用docker run命令启动容器,配置了GPU资源、内存共享、端口映射等参数,特别指定了模型路径、并行计算、内存利用率等关键参数。该方案实现了大模型在内网环境的安全高效部署,适用于需要离线运行的AI推理场景。

qq_42881308的博客 1052

HDU-4126(Genghis Khan the Conqueror)

Problem Description Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元太祖), was the founder of the Mongol Empire and the greatest conqueror in Chinese hist...

qq_44641782的博客 407

岭回归的MATLAB步骤

MATLAB 实现框架,它涵盖了从数据导入到岭回归的步骤,包括计算共线性、使用 MAE、MSE、R²、MAPE 进行评价,以及绘制相应的可视化图表。

subject625Ruben的博客 1095

HDU - 4126 Genghis Khan the Conqueror

HDU - 4126 Genghis Khan the Conqueror 树形dp+MST 题目描述 Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元太祖), was the founder of the Mongol Empire and the gr...

1262934560的博客 497

卫星监测“America”级#两#栖#攻#击#舰#(LHA-6)出港

卫星监测“America”级#两#栖#攻#击#舰#(LHA-6)出港 前脚刚走,后脚又来,山姆大叔又来刷存在感,2020年7月28日,USS Ronald Reagan流窜在我国东海海区被卫星拍了下来: 2020年8月1日,最新卫星图像显示USS Ronald Reagan已经返回母港日本横须贺:距离其出港(2020年6月8日)已经过去了快两个月 然而事情并没有到此结束,“America”级#两#栖#攻#击#舰#(LHA-6)选择在 “八.一” 这个特殊的日子前后出港颇具挑衅的味道。 根据2020年

qq_46071146的博客 1573

YOLOv8 ultralytics使用笔记----labelme标记数据,训练模型、追踪目标。

Ultralytics是一个Python库,它是为执行高级计算机视觉任务而创建的,如对象检测、实例分割、图像分类等。Ultralytics为YOLO模型发布了一个全新的存储库,它被构建为用于机器视觉统一框架。这里先利用,并激活。

qq_48050838的博客 1万+

hdu-4126 Genghis Khan the Conqueror(最小生成树+树形dp)

题目链接: Genghis Khan the Conqueror Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others) Problem Description Genghis Khan(成吉思汗)(1162-1227), also known by his birth ...

weixin_30815427的博客 197

AS7341光谱传感器实战:如何用STM32F103精准测量环境色温(附完整代码)

本文详细介绍了如何使用STM32F103驱动AS7341光谱传感器实现环境色温的精准测量。从硬件连接到驱动开发,再到色温计算算法的实现,提供了完整的代码示例和优化建议,帮助开发者在智能照明、农业监测等领域快速应用AS7341进行高精度色温检测。

weixin_30352645的博客 485

HDU4126Genghis Khan the Conqueror(最小生成树+并查集)

Genghis Khan the Conqueror Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total Submission(s): 1687    Accepted Submission(s): 501 Problem Description G

青山绿水之辈 专栏 1575

MacBook 本地化部署 Dify 指南

dify 怎么安装部署 有哪些坑 !

weixin_44542598的博客 1536

低光照图像增强:从传统方法到深度学习

低光照图像增强:从传统方法到深度学习​ 人工智能,计算机视觉,大模型,AI,本文聚焦视觉模型的偏差与公平性问题,阐述了偏差在性别、种族、年龄等方面的表现及对医疗、司法、安防等领域的影响。分析了偏差源于数据采集与标注问题及算法局限。介绍了准确率差异等公平性评估指标、相关数据集和工具,还给出数据处理、算法改进、模型训练等避免歧视的策略,并附代码示例与实际案例,为提升视觉模型公平性提供多方面参考。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 2万+

hdu 4126 Genghis Khan the Conqueror

prim + 树形dp,首先用prim预处理,建出最小生成树,然后,如果更新的不是最小生成树上的边,那么新图中的最小生成树即为原来的最小生成树。如果更新的为最小生成树上的边,则我们需要考虑两个方面:        1、将原来最小生成树的边,换成新边的新生成树的长度。        2、把原来的边删除,原图上从新生成最小生成树。 第一个问题比较容易解决,直接用原生成树,算就可以。仔细想一下第二

ok_again的专栏 1983

Algorithm:【算法进阶之路】之算法面试刷题集合—数据结构的简介、最强学习路线(逻辑结构【数组-链表-栈和队列/树-图-哈希】、物理结构【元素/关系】、数据运算【十大排序/四大查找-图三大搜索-

​ Algorithm:【算法进阶之路】之算法面试刷题集合—数据结构的简介、最强学习路线(逻辑结构【数组-链表-栈和队列/树-图-哈希】、物理结构【元素/关系】、数据运算【十大排序/四大查找-图三大搜索-树三大遍历】、高级算法【枚举/回溯/递归/分治/动规/贪心】)、问题为导向的十大类刷题算法总结之详细攻略 目录 相关文章 数据结构思维导图 基本术语 一、数据结构的概述 二、数据的逻辑结构 三、数据的物理结构 四、数据的运算

头部AI社区如有邀博主AI主题演讲请私信—心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,专注,谦虚,自律,反思,成长,还算比较正能量的博主,公益免费传播…内心特别想在AI界做出一些可以推进历史进程影响力的技术(兴趣使然,有点小情怀,也有点使命感呀 6862

hdu4126Genghis Khan the ConquerorGenghis Khan the Conqueror(MST+树形DP)

题目请戳这里 题目大意:给n个点,m条边,每条边权值c,现在要使这n个点连通。现在已知某条边要发生突变,再给q个三元组,每个三元组(a,b,c),(a,b)表示图中可能发生突变的边,该边一定是图中的边。c表示该边新的权值,c只可能比原来的权值大。给的q条边发生突变的概率是一样的。求突变后连通n个点最小代价期望值。 题目分析:如果没有那条突变的边,就是求一个mst。但是因为有一条边要突变,每条边

ophunter的专栏 1675

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

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

hdu 4126 Genghis Khan the Conqueror (MST+树形dp)

Genghis Khan the Conqueror Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total Submission(s): 1208    Accepted Submission(s): 332 Problem Descript

To be what you what to be! 1972

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

HDU - 4126 Genghis Khan the Conqueror MST+树形DP

题意: 一个N个点的无向图,先生成一棵最小生成树,然后给你Q次询问,每次询问都是x,y,z的形式, 表示的意思是在原图中将x,y之间的边增大(一定是变大的)到z时,此时最小生成数的值是多少。最后求Q次询问最小生成树的平均值。 N<=3000 , Q<=10000 分析: 先用kruskal算法找到最小生成树,并求出总花费sum.再以枚举n个点,依次作为树根dfs,dp[i][j]...

兜率工的博客 311

lwip-2.0.3

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

HDU 4126 Genghis Khan the Conqueror MST+最佳替代边

题目大意:给你一个无向图,其中有些边有可能增大且每次只增大一条便,每条便增大的可能性相等,问最后产生的最小生成树的期望值为多少。 解题思路:近似与次小生成树的思路,先找一个最小生成树,并找出当生成树中的树边的最佳替代边, 如果增大的边为树边,用增大以后的边和最佳替代边做比较选择性替代,加上新生成树的总边权。 不然就不用做修改,直接加上原树的边权就好。 唯一的难点就是找最佳替代边,之

Veda_的专栏 716

Hdu-4126 Genghis Khan the Conqueror //MST+树形dp

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4126 题意 简而言之,就是给你一张图(稠密图),现在有 QQQ 次修改,每次依原图更改一条边的权值(只会比原图的大),让你求出每次更改后的最小生成树权值,取这 QQQ 次最小生成树权值的平均值 思路 我们先不考虑修改,就是求出原图的最小生成树,由于是稠密图,所以一般用 primprimprim 算法,...

wqq的博客 251

HDU 4126 Genghis Khan the Conqueror (树形DP + MST)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4126 题意:给n个点,m条边,每条边权值c,现在要使这n个点连通。现在已知某条边要发生突变,再给q个三元组,每个三元组(a,b,c),(a,b)表示图中可能发生突变的边,该边一定是图中的边。c表示该边新的权值,c只可能比原来的权值大。给的q条边发生突变的概率是一样的。求突变后连通n个点最小代价...

Tongqi 705

HDU 4126 Genghis Khan the Conqueror MST+树形dp

题意: 给定n个点m条边的无向图。 下面m行给出边和边权 下面Q个询问。 Q行每行给出一条边(一定是m条边中的一条) 表示修改边权。 (数据保证修改后的边权比原先的边权大) 问:修改后的最小生成树的权值是多少。 每个询问互相独立(即每次询问都是对于原图修改) 保证没有重边。 求:所有修改后的最小生成树权值的平均值。 思路: 首先跑一个最小生成树。 求得这个MST的

九野的博客 1282

HDU 4126 Genghis Khan the Conqueror MST + 树形DP 2011年福州现场赛F题

题目大意: 就是现在给出一个图, N个点, M条边, N 现在给出Q次询问, 每次询问表示如果更改边(u, v)的权值为c, c一定比之前那个权值大, 那么改变这条边之后得到的图的最小生成树的权值是多少 输出Q次查询对应MST的权值的和除以Q, 保留小数点后4位 大致思路: 首先我们可以用Prim预处理出原图的最小生成树, 那么记录这颗树上使用的边 如果更改发生在不是最小生成

Gatevin的专栏 793

HDU 4126 Genghis Khan the Conqueror(树形dp,MST,破坏原有最小生成树边后的最小生成树代价)

题目链接: HDU 4126 Genghis Khan the Conqueror 题意: 给nn个点和mm条无向边,需要将这nn个点连通。但是有QQ次破坏,每次破坏会把mm条边中的某条边的权值增大,求QQ次破坏每次将nn个点连通的代价的期望?(每次破坏后的最小生成树的代价累加除以QQ) 数据范围:n≤3000,Q≤104,单边权≤107,总边权≤109n\leq 3000,Q\leq

ramay7 1144

hdu4126.Genghis Khan the Conqueror

http://acm.hdu.edu.cn/showproblem.php?pid=4126 题意:给一个图(V 思路:一个不知道怎么证的引用:新的生成树可以与原生成树相最多只有一条边的不同,而且不同的那条边就是被修改的边。那么每次修改后的询问就是去掉被修改的边,然后求出两个树最近的点。又有其中一棵子树一定包含他所有的子节点,那么就可以先用树dp求出一个点与一棵子树的最小距离,即求出dp[i]

Grastyele 2336
上一篇: HDU 4135 Co-prime(容斥原理)
下一篇: 食物链 POJ - 1182(种类并查集)
coldfresh
博客等级 码龄10年 107粉丝 405原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值