题解 | Travel Dream-2019牛客暑期多校训练营第十场I题

【NOIP2013模拟联考9】旅行者问题 旅行者问题problemDescriptionInputOutputSample InputSample OutputData Constraint思路 problem Description lahub是一个旅行者的粉丝,他想成为一个真正的旅行者,所以他计划开始一段旅行。lahub想去参观n个目的地(都在一条直道上)。lahub在起点开始他的旅行。第i个目的地和起点的距离为ai千米(ai为非负整数)。不存在两个目的地和起点的距离相同。 从第i个目的地走到第j个目的地所走的路程为 |ai-aj|千米。我们把 阅读详情

题目来源于牛客竞赛:https://ac.nowcoder.com/acm/contest/discuss
题目描述:
在这里插入图片描述
输入描述:
在这里插入图片描述
输出描述:
在这里插入图片描述
示例1:
在这里插入图片描述
示例2:
在这里插入图片描述
题解:
在这里插入图片描述
在这里插入图片描述
代码:

#include<bits/stdc++.h>
using namespace std;
const int inf=1000000007;
int a[305][305],d[2][305][305],n,m,x[305],y[305],z[305],k,f[305],ans;
int w[305][305][3],o;
const int T=1000;
mt19937 gen(time(0)^19260817);
void Max(int &x,int y){if (y>x) x=y;}
void ins(int x,int y,int z){
    int p=0;
    while (p<3){
        int u=w[x][y][p];
        if (a[x][u]+a[u][y]<a[x][z]+a[z][y]) break;
        p++;
    }
    if (p<3){
        for (int i=2;i>p;i--) w[x][y][i]=w[x][y][i-1];
        w[x][y][p]=z;
    }
}
void work(int x,int y,int u,int v){
    int p=0;
    while (w[u][v][p]==x||w[u][v][p]==y) ++p;
    int z=w[u][v][p];
    Max(d[o][x][y],a[x][u]+a[u][z]+a[z][v]+a[v][y]);
}
void solve(int k){
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            d[o][i][j]=-inf;
    if (k==1){
        for (int i=1;i<=n;i++) if (f[i]==o) d[o][i][i]=0;
    } else if (k==2){
        for (int i=1;i<=n;i++) if (f[i]==o)
        for (int j=1;j<=n;j++) if (i!=j&&f[j]==o)
            d[o][i][j]=a[i][j];
    } else if (k==3){
        for (int i=1;i<=m;i++) if (f[x[i]]==o&&f[y[i]]==o)
        for (int j=1;j<=m;j++) if (f[x[j]]==o&&f[y[j]]==o){
            if (i==j) continue;
            if (x[i]==x[j]) Max(d[o][y[i]][y[j]],z[i]+z[j]);
            else if (x[i]==y[j]) Max(d[o][y[i]][x[j]],z[i]+z[j]);
            else if (y[i]==x[j]) Max(d[o][x[i]][y[j]],z[i]+z[j]);
            else if (y[i]==y[j]) Max(d[o][x[i]][x[j]],z[i]+z[j]);
        }
    } else if (k==4){
        for (int i=1;i<=m;i++) if (f[x[i]]==o&&f[y[i]]==o)
        for (int j=1;j<=m;j++) if (f[x[j]]==o&&f[y[j]]==o){
            if (i==j) continue;
            if (x[i]==x[j]) continue;
            if (x[i]==y[j]) continue;
            if (y[i]==x[j]) continue;
            if (y[i]==y[j]) continue;
            if (x[i]!=x[j]) Max(d[o][x[i]][x[j]],z[i]+z[j]+a[y[i]][y[j]]);
            if (x[i]!=y[j]) Max(d[o][x[i]][y[j]],z[i]+z[j]+a[y[i]][x[j]]);
            if (y[i]!=x[j]) Max(d[o][y[i]][x[j]],z[i]+z[j]+a[x[i]][y[j]]);
            if (y[i]!=y[j]) Max(d[o][y[i]][y[j]],z[i]+z[j]+a[x[i]][x[j]]);
        }
    } else if (k==5){
        for (int i=1;i<=n;i++) if (f[i]==o)
        for (int j=1;j<=n;j++) if (f[j]==o)
            w[i][j][0]=w[i][j][1]=w[i][j][2]=0;

        for (int i=1;i<=m;i++) if (f[x[i]]==o&&f[y[i]]==o)
        for (int j=1;j<=m;j++) if (f[x[j]]==o&&f[y[j]]==o){
            if (i==j) continue;
            if (x[i]==x[j]) ins(y[i],y[j],x[i]);
            else if (x[i]==y[j]) ins(y[i],x[j],x[i]);
            else if (y[i]==x[j]) ins(x[i],y[j],x[j]);
            else if (y[i]==y[j]) ins(x[i],x[j],y[j]);
        }
        for (int i=1;i<=m;i++) if (f[x[i]]==o&&f[y[i]]==o)
        for (int j=1;j<=m;j++) if (f[x[j]]==o&&f[y[j]]==o){
            if (i==j) continue;
            if (x[i]==x[j]) continue;
            if (x[i]==y[j]) continue;
            if (y[i]==x[j]) continue;
            if (y[i]==y[j]) continue;
            work(x[i],x[j],y[i],y[j]);
            work(x[i],y[j],y[i],x[j]);
            work(y[i],x[j],x[i],y[j]);
            work(y[i],y[j],x[i],x[j]);
        }
    }
    if (k!=1) for (int i=1;i<=n;i++) d[o][i][i]=-inf;
}

int main(){
    cin >> n >> m >> k;
    for (int i=0;i<=n;i++)
        for (int j=0;j<=n;j++)
            a[i][j]=-inf;
    for (int i=1;i<=m;i++){
        cin >> x[i] >> y[i] >> z[i];
        a[x[i]][y[i]]=a[y[i]][x[i]]=z[i];
    }
    for (int _=0;_<T;_++){
        for (int i=1;i<=n;i++) f[i]=gen()%2;
        if (k==6){
            o=0; solve(2); o=1; solve(4);
        } else {
            o=0; solve(k/2); o=1; solve(k-k/2);
        }
        for (int i=1;i<=m;i++) if (f[x[i]]^f[y[i]]){
            if (f[x[i]]) swap(x[i],y[i]);
        }
        for (int i=1;i<=m;i++) if (f[x[i]]^f[y[i]])
        for (int j=1;j<=m;j++) if (f[x[j]]^f[y[j]]){
            //if (x[i]==x[j]||y[i]==y[j]) continue;
            ans=max(ans,d[0][x[i]][x[j]]+d[1][y[i]][y[j]]+z[i]+z[j]);
        }
    }
    if (ans>0) cout << ans << endl; else puts("impossible");
    return 0;
}

更多问题,更详细题解可关注牛客竞赛区,一个刷题、比赛、分享的社区。
传送门:https://ac.nowcoder.com/acm/contest/discuss

[某人的题解]徒步旅行(travel) 题目描述 小 A 决定开始一场奇妙的徒步旅行,旅行地图可以看成是一个平面直角坐标系,小 A 从家O(0,0)O(0, 0)O(0,0)出发,每一步移动只能由他此时所在的位置(x,y)(x,y)(x,y)走到以下四个坐标之一:(x−1,y),(x,y−1),(x+1,y),(x,y+1)(x-1,y),(x,y-1),(x+1,y),(x,y+1)(x−1,y),(x,y−1),(x+1,y),(x,y+1)。 现在有nnn个旅游景点,第iii个旅游景点位置为(xi ,yi)。 由于世界如此之大,整个旅行地图 阅读详情

相关推荐

哨兵一号数据下载

哨兵1号数据的下载过程

weixin_59617499的博客 5145

2019年华南理工大学程序设计竞赛(春季赛)E:数独挑战(dfs)

【题解】 搜索每一种可能,输出可行方案即可。 【代码】 #include <bits/stdc++.h> using namespace std; int mp[12][12]; bool check(int cnt) { int x=cnt/9,y=cnt%9; for(int i=0;i<9;i++) if(mp[x][i]==mp[x][y...

菜鸡成长史 627

【NVIDIA Jetson Orin系列 - 安装NVIDIA SDK Manager】

NVIDIA Jetson Orin - 安装NVIDIA SDK Manager

dally2的博客 2702

寒武纪测试赛E题题解-Travel

链接:http://aiiage.hustoj.com/contest.php?cid=1000 题意: 给你n(n 第一行输入n,表示n个点 接下来n-1行,输入u,v,w,表示一条边,w是权值,点从1开始 输入一个Q,表示询问次数(Q 接下来Q行,输入u,k(2 对于每次询问,输出在距离mod k的意义下,距离 u 点最远的点有多远 样例如下: 输入: 3 1 2 7 1

mMingfunnyTree的博客 1347

【实战学习(五)】开源项目学习之uWSGI的部署以及配合nginx

文章目录1)uWSGI是什么?1.1 WSGI1.1.1 Application端1.1.2 Server端1.1.3 WSGI中间件1.2 uwgi1.3 uWSGI、WSGI、uwsgi之间的关系*为什么有了uWSGI为什么还需要nginx?2)连接uwsgi和Django*避坑之Windows10安装uWSGI非常极其艰难,最好勿浪费时间,直接转战Linux吧:2.1 uWGI部署2.1.1 在虚拟环境下安装uwsgi:2.1.2 测试uWSGI的运行2.1.3 使用uWSGI运行Django项目2.

黑黑白白君的博客 1515

循环神经网络(RNN)

在之前学习了全连接神经网络(DNN)模型,网络结构都是从输入层到隐含层再到输出层,层与层之间是全连接或部分连接的,但每层之间的节点是无连接的。 一、神经网络基础 神经网络可以当做是能够拟合任意函数的黑盒子,只要训练数据足够,给定特定的x,就能得到希望的y,结构图如下: 将神经网络模型训练好之后,在输入层给定一个x,通过网络之后就能够在输出层得到特定的y,那么既然有了这么强大的模型,为什么还需要RNN(循环神经网络)呢? 二、为什么需要RNN(循环神经网络) 考虑这样一个问题,如果要预测句子的下一个单词是什么

小朱小朱绝不认输的博客 2万+

牛客网国庆集训派对Day3 H-Travel(计数问题)

思路来源 https://blog.csdn.net/Enterprise_/article/details/81462003 题解 因为这m次旅游互不相干,所以在这n-1条边里选m-1条边将其割断,将原树划分为m块即可。 总方案数考虑顺序,取这m块的全排列即可。 由于原图是一棵树,显然与怎么连无关,所以输入部分多余。 心得 学了卢卡斯定理之后,总想用卢卡斯,实际上用不到。 ...

小衣同学的博客 458

GEE:基于 Landsat 数据集生成(1986-2024)月度合成地表温度(LST)时间序列数据

CSDN@_养乐多_本文将介绍使用 Landsat 时间序列计算(1986-2024)月度合成地表温度(LST)时间序列数据集的代码。

养乐多的博客 1723

连通图 题解

连通图 题目 判断一个图是否为一个连通图 输入 n 顶点个数 ( n <= 100 ) 点与点之间的边 输出 1 表示连通 0 表示不边通 样例 input 5 1 2 2 3 5 4 0 0 output 0 解题思路 建一个邻接表,从任意一个点走起,将所有点走一遍,如果能就输出 1 ,不能就输出 0 。 代码 #include<iostream> #include<...

Y的博客 432

MATLAB算法实战应用案例精讲-【数模应用】装箱问题

装箱问题可以根据不同的维度进行分类。以下是一些常见的装箱问题二维装箱问题:二维装箱问题假设所有物品都是平面上的矩形,并且需要将它们放入平面上的容器中。这个问题的目标是找到一种装箱方案,使得物品不重叠并占据的总面积最小。三维装箱问题:三维装箱问题考虑到物品可以具有高度,并且需要将它们放入三维容器(如箱子或货柜)中。目标是找到一种装箱方案,使得物品不重叠且总体积最小。多维装箱问题:多维装箱问题是指在更高维度空间中进行装箱的问题。除了长度和宽度之外,物品可能具有其他属性,如高度、重量、形状等。

qq_36130719的博客 1576

优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信

优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信今天开始会陆续介绍一些优秀的开源项目,项目基本都是和FPGA或HDL相关的。对于一些找工作或者急需项目经验的人来说,这些项目...

OpenFPGA的博客 8125

旅行计划(题解)

【问题描述】就要放暑假了。忙碌了一个学期的Sharon 准备前往W 国进行为期长达一个月的旅行。然而旅行往往是疲惫的,因此她需要来规划一下自己的旅行路线。W 国由n 个城市组成,我们不妨将每个城市看成是一个二维平面上的点。对于第i 个城市,我们设它所处的位置为( , ) i i x y 。W 国的人做事一向循规蹈矩,因此在从城市i 向城市j 移动的过程中,只能沿水平或竖直方向移动。换句话...

dianminba7855的博客 437

Python爬虫博客:爬取碳排放交易数据——使用最新技术的完整实现

通过上述方法,我们可以构建一个高效的爬虫,爬取碳排放交易市场的数据并进行分析。这个项目不仅展示了如何处理静态和动态网页,还提供了如何存储数据、分析数据和可视化结果的技巧。随着爬虫技术的不断进步,我们可以进一步提升爬取效率和数据分析能力。如果你希望更深入了解如何进行数据挖掘和机器学习分析,可以尝试将碳排放数据与其他经济数据结合,利用机器学习模型进行趋势预测或决策支持。

2201_76125261的博客 358

Wannafly挑战赛2 B Travel(dij)

题目链接:https://www.nowcoder.com/acm/contest/17/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 精灵王国有N座美丽的城市,它们以一个环形排列在Bzeroth的大陆上。其中第i座城市到第i+1座城市花

far away 803

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

jre9下载 jdk9

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

C++ 2017提高组C++初赛试题(答案版)

CCF NOIP2016 初赛提高组C++语言试题第 1 页,共10 页第二十三届全国青少年信息学奥林匹克联赛初赛提高组C++语言试题竞赛时间:2017 年10 月14 日14:30~16:30选手注意: 试题纸共有10 页,答题纸共有2 页,满分100 分。请在答题纸上作答,写在试题纸上的一律无效。 不得使用任何电子设备(如计算器、手机、电子词典等)或查阅任何书籍资料。一、单项选择...

weixin_30607659的博客 1882

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

牛客网暑期ACM多校训练营(第二场): H. travel(树形线头DP)

链接:https://ac.nowcoder.com/acm/contest/140/H 来源:牛客网   题目描述 White Cloud has a tree with n nodes.The root is a node with number 1. Each node has a value. White Rabbit wants to travel in the tree 3 ti...

加载中... 530

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

【qduoj - 夏季学期创新题】骑士游历(递推dp)

 题干: 描述   输入   输入包含多组数据,第一行T表示数据组数接下来每行六个整数n,m,x1,y1,x2,y2(分别表示n,m,起点坐标,终点坐标) 输出   输出T行,表示起点到终点的路径数 输入样例 1  1 30 30 1 15 3 15 输出样例 1 2 解题报告:     这题刚开始想用dfs来写,结果发现数字一大,连结果都跑不出来,再看题、、马...

xuanweiace的博客 629

牛客网 又见斐波那契 矩阵快速幂

题目链接 链接:https://ac.nowcoder.com/acm/contest/105/G 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 这是一个加强版的斐波那契数列。 给定递推式 求F(n)的值,由于这个值可能太大,请对10^9+7取模。 输入描述: 第一行是一个...

RPG_Zero的博客 289

PAT-A1030 Travel Plan 题目内容及题解

A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b...

BourbonWhiskey 的博客 543

HDOJ 4284-Travel解题报告

亚洲区天津赛区网络预选赛的一道题,简单的搜索,但是搜索的时候最好把开始点1拆为两个节点,如果1不是必经节点,那么拆不拆都无所谓,如果1是必经节点,那么在刚开始在1的时候选择工作还是到最后再工作就要分情况,所以要进行拆点。 View Code 1 #include<iostream> 2 #include<cstdio> 3 #include&l...

weixin_30647065的博客 132

牛客多校第二场 H travel(树形dp)

链接:https://www.nowcoder.com/acm/contest/140/H 来源:牛客网   题目描述 White Cloud has a tree with n nodes.The root is a node with number 1. Each node has a value. White Rabbit wants to travel in the tree 3 ti...

Lee_w_j__的博客 688

2020牛客多校第十场I-Tournament

Decription Solution 首先,看到这题会有一种冲动 怎么办! 问题在于,我们让第一个人尽快离开,其他人等了很久 我们把它拆成四部分 记住最优宗旨要让所有人尽量一块一块地出现 Case 1 前1→n21 \rightarrow \cfrac{n}{2}1→2n​个人互相比 要让所有人尽量一块一块地出现 For instance,n=10 premulationpremulationpremulation 121\qquad212 131\qquad313 232\q

ding_ning123的博客 474

牛客网暑期ACM多校训练营(第二场)H.travel

题解:dp[i][j][k]代表当前为第i个点,以i为根的子树上有j条链,其中有k条是跟当前根节点相连接的。故k最多为2,j最多为4。因为可能有2条同时连上i,这种是算作一条的。 因为正向跑同一个子树会统计多次,所以倒着跑。 #include"bits/stdc++.h" using namespace std; typedef long long LL; const int MX = 4e5...

qq_18869763的博客 408

牛客网多校2 travel(树形dp)

题目:给你一棵你个点的树,每个点有一个价值,选出三条不相交的链使得最后的总价值最大。 显然是树形dp,我定义了一个三维的dp[i][j][k](i为子树id,j为选择了几条链,k为选择的j条链中是否包含了经过i点的直链)(0&lt;=j&lt;=3,0&lt;=k&lt;=1)。 昨晚写这个题的时候一直就是过48%的数据,真是烦啊,今天发现定义一个全局变量的数组,里面递归时出错,真是无语了。改...

XFire的博客 522
上一篇: 题解 | Stammering Chemists-2019牛客暑期多校训练营第十场H题
下一篇: 题解 | Wood Processing-2019牛客暑期多校训练营第十场J题
牛客竞赛
博客等级 码龄7年 9粉丝 97原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值