UVa 10917 Walk Through the Forest(最短路+DP)

银河麒麟系统安装redis【亲测可行】 架构:Linux 5.10.0-9-generic x86_64 GNU/Linux。redis版本:redis-6.2.3.tar.gz。然后在执行make install,结束;OS:银河麒麟V10(SP1)未激活。cpu:I5-10代; 阅读详情

求出办公室到每一点的最短路d[i],然后记忆话搜索,dp[i]由和i点相邻且d[j]<d[i]的点更新,是树形DP


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define INF 10000000
using namespace std;
int N,M;
struct edge{
    int s,t,c;
};

vector <edge> E;
vector <int> G[1005];
int d[1005];
bool vis[1005];
int p[1005];

int dp[1005];

int solve(int n){
    if(dp[n]) return dp[n];
    for(int i=0;i<G[n].size();i++){
        edge &tmp=E[G[n][i]];
        if(d[tmp.t]<d[n]){
           dp[n]+=solve(tmp.t);
        }
    }
    return dp[n];
}


void addedge(int s,int t,int cost){
    E.push_back(edge{s,t,cost});
    G[s].push_back(E.size()-1);
}

struct HNode{
    int d,u;
    bool operator <(const HNode &obj)const{
        return d>obj.d;
    }
};

void Dij(int s){
    for(int i=1;i<=N;i++){
        d[i]=INF;
    }

    d[s]=0;
    memset(vis,0,sizeof(vis));
    priority_queue<HNode> Q;
    Q.push(HNode{0,s});
    while(!Q.empty()){
        int u=Q.top().u;
        Q.pop();
        if(vis[u]) continue;
        vis[u]=1;
        for(int i=0;i<G[u].size();i++){
            edge &tmp=E[G[u][i]];
            if(d[tmp.t]>d[u]+tmp.c){
                d[tmp.t]=d[u]+tmp.c;
                p[tmp.t]=u;
                Q.push(HNode{d[tmp.t],tmp.t});
            }
        }
    }
}


int main(){
    while(~scanf("%d",&N)){
        for(int i=1;i<=N;i++){
            G[i].clear();
        }
        E.clear();
        if(!N) break;
        scanf("%d",&M);
        for(int i=0;i<M;i++){
            int s,t,c;
            scanf("%d%d%d",&s,&t,&c);
            addedge(s,t,c);
            addedge(t,s,c);
        }
        Dij(2);
        memset(dp,0,sizeof(dp));
        dp[2]=1;
        solve(1);
        for(int i=1;i<=N;i++){
            //cout<<i<<' '<<dp[i]<<endl;
        }
        printf("%d\n",solve(1));
    }
    return 0;
}


告别“盲开”:手把手教你用MCU内置比较器搞定BLDC无感方波启动(附代码片段) 本文详细介绍了如何利用MCU内置比较器实现BLDC无感方波启动,解决传统无传感器控制中的'盲开'问题。通过虚拟中性点电路设计和三段式启动流程,结合反电动势检测和过零检测技术,提供了一套经济高效的解决方案,并附有可直接移植的代码片段,助力工程师快速实现可靠的无感控制。 阅读详情

相关推荐

一本集成电路静态时序设计经典之作(可下载)

本书全面深入探讨集成电路设计中关键技术的专著,涵盖了从基础知识到高级应用的各个方面。本书详细介绍了集成电路的发展历程、**静态时序分析的重要性、基本时序模型、时序信息库文件的构建、时序约束的设置、串扰噪声的影响及其控制方法**,并通过实战案例展示了如何进行有效的时序分析和优化。

nuoweishizi的博客 851

UVA10917 Walk Through the Forest

Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office

algzjh的博客 700

哨兵一号burst数据的下载和处理

在Sentinel - 1数据处理领域,其基本流程起始于从(ASF)下载原始压缩文件。这些文件规模颇为可观,常规大小约4GB,而部分数据的原文件甚至已攀升至7GB,对存储空间提出了严苛要求。从影像构成来看,每景Sentinel - 1影像由三个干涉宽幅(IW)模式子带组成,每个IW一般包含9个脉冲串(burst)。然而,在实际研究中,我们所关注的研究区域往往仅占据其中寥寥几个burst。

kangkangluoluo的博客 1965

UVa10917 Walk Through the Forest

题目描述 传送门根据题目意思建立DAG,再统计路径条数。代码#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> using namespace std; const int maxn=1005,maxm=(maxn-1)*(maxn-2); const int INF=1e

VSEJGFB的博客 424

RK3588S开发板实战:手把手教你调试IMX415摄像头(附常见问题排查)

本文提供了基于RK3588S开发板调试IMX415摄像头的完整实战指南。从硬件连接到软件配置,详细解析了设备树(DTS)设置、驱动加载验证及V4L2工具链使用,并附带了常见问题排查方法,帮助开发者快速解决摄像头调试中的典型问题,实现图像采集与性能调优。

assembly8low的博客 598

微磁模拟实战指南:从OOMMF安装到首个3D模型运行

本文详细介绍了OOMMF微磁模拟软件的安装与使用,从环境配置到首个3D模型运行的完整教程。涵盖Windows、Linux和macOS平台的安装避坑指南,以及MIF文件编写、并行计算优化等实战技巧,帮助研究人员快速掌握这一开源工具在磁畴壁运动、磁滞回线等微磁学问题中的应用。

weixin_29294597的博客 153

UVA 10917 - Walk Through the Forest(最短路优化DP)

题目链接:点击打开链接 题意:给你一个图, 从1走到2,求有多少种不同的走法,从结点a可以走到b的条件是:存在一条总b出发回家的路径,比从a出发回家的路径都短。 思路:这个条件的意思其实就等价于从2到b的最短路比从2到a的最短路短。 所以, 可以事先处理出从2出发到所有结点的最短路。 然后用DP进行计数就行了。 细节参见代码: #include #include #include #in

AC_Arthur的专栏 2407

STM32 热敏电阻测量温度

1、硬件 STM32F103C8T6、热敏电阻传感器、OLED。 2、热敏电阻传感器的介绍

weixin_54721788的博客 1万+

UVA 10917 Walk Through the Forest(最短路+dp)

题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1858 题目大意:n个节点,公司是1号,家是2号。他从公司走回家,走的时候他有个规则,那就是:一条a到b,如果b到家的存在一条路都比从a到家的任何一条路要短,那么这条路可以走,否则就不能走。问你从 2

沉溺的专栏 775

避开内存陷阱:手把手教你用RKNN零拷贝接口正确管理输入输出Tensor

本文深入解析RKNN零拷贝接口在边缘计算中的高效内存管理策略,通过YOLOX实例演示如何避免内存对齐错误和数据错位。详细介绍了`rknn_tensor_mem`系列API的正确使用方法,包括内存创建、绑定、释放全流程,以及性能优化技巧如内存池技术和多核NPU负载均衡,帮助开发者提升推理效率并避开常见陷阱。

weixin_33686714的博客 160

从零到一:Python+Playwright 实现动态网站全量数据采集实战(附反爬对抗与性能优化)

在动手之前,先明确武器优势: 2. 项目结构规划 为了代码可维护性,我们采用模块化结构: 三、核心实战:构建动态采集器 第一步:初始化“隐身”浏览器 普通启动容易被检测,我们需要注入一段 JS 脚本来抹除自动化特征。 第二步:处理无限滚动与动态加载 这是动态网站的核心难点。我们需要模拟人类滚动,并等待新数据加载完成。 第三步:登录态保持与复用 避免每次运行都重新登录。我们将 Cookie 保存到本地,下次直接加载。 第四步:主流程编排 将上述模块串联起来,并加入异常重试机制。 四、进阶优化:性能与反爬

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1164

uva 10917 Walk Through the Forest(最短路+DP路径,4级)

Description Problem C: A Walk Through the Forest Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he lik

nealgavin的专栏 2130

Python 爬虫实战:解析 JSON 数据爬取今日头条热点新闻(API 接口逆向与字段提取)

在当今信息爆炸的时代,新闻资讯的获取变得尤为重要。今日头条作为国内领先的新闻聚合平台,其热点新闻数据具有很高的价值。本文将详细介绍如何通过 Python 爬虫技术,逆向解析今日头条的 API 接口,提取并解析 JSON 数据,最终获取热点新闻信息。

yansideyucsdn的博客 3210

Uva 10917 - Walk Through the Forest (最短路+DP)

题目链接 https://vjudge.net/problem/UVA-10917 【题意】 gbn最近打算穿过一个森林,但是他比较傲娇,于是他决定只走一些特殊的道路,他打算只沿着满足如下条件的(A,B)道路走:存在一条从B出发回家的路,比所有从A出发回家的路径都短。你的任务是计算一共有多少条不同的回家路径。其中起点的编号为1,终点的编号为2. 【思路】 现求出以家为源点的所有点的最短路...

Change the world by program. 480

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

深度学习工具包 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】10917 A Walk Through the Forest 最短路+DP

Problem C: A Walk Through the Forest Jimmy experiences a lot of stress at work these days, especially sincehis accident made working difficult. To relax after a hard day, helikes to walk home. To

poursoul 1237

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

UVA 10917 Walk Through the Forest 最短路 + DP

求出最短路后,如果d[A]<d[B] 则B可以走向A 是个DAG。 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm&gt...

weixin_34293246的博客 67

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

UVA - 10917 Walk Through the Forest (最短路+DP)

Description Problem C: A Walk Through the Forest Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to

那些年 1072

UVA 10917 - Walk Through the Forest(最短路`dijksta+DP)

题目: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=74214#problem/B 题意: n个点,m条无向边,求出从起点1到终点2的最短路径有几条. 思路: 先使用dijkstra求出最短路径树. 然后将d[a] , 从而得到DAG, 然后可以是DP, 记忆化搜索. AC. #include #include #

Halo 677

uva 10917 - Walk Through the Forest(最短路+记忆化)

题目链接:uva 10917 - Walk Through the Forest 做一遍最短路,记录下所有点到终点的距离,然后重新建图,如果d[u] #include #include #include #include #include using namespace std; typedef pair pii; typedef long long ll; co

不慌不忙、不急不躁 1316

UVA 10917 Walk Through the Forest

最短路+DP Walk Through the Forest Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status]   Description

码代码的猿猿 1140

uva 10917 Walk Through the Forest(最短路)

uva 10917 Walk Through the Forestgbn最近打算穿过一个森林,但是他比较傲娇,于是他决定只走一些特殊的道路,他打算只沿着满足如下条件的(A,B)道路走:存在一条从B出发回家的路,比所有从A出发回家的路径都短。你的任务是计算一共有多少条不同的回家路径。其中起点的编号为1,终点的编号为2. Input多组数据输入,每组数据第一行输入n,m(1<=n<=1000)表示点的

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 1310

uva 10917 Walk Through the Forest

d[i]表示从i点到家的距离,如果d[i] > d[j[且i,j之间存在路的话,那么就可以走i->j。最后问从起点到终点有几条不同的路径。 首先用dijkstra求出每一点到终点的距离。 然后建立新图,如果

Jane的私房菜 546

Walk Through the Forest UVA - 10917 DAG上的图

居然AC 了,, 越来越不自信了。。 还以为自己在dfs的时候肯定会有地方错。。。然后用dp的时候可能也会错。。 结果过了。。 这道题让我对于DAG的dp算法有了跟进一步的了解。。。 #include #include #include #include #include #include #include #include #include #include #

now_ing的博客 302
上一篇: POJ 1006 I Think I Need a Houseboat(二分)
下一篇: UVa 11374 Airport Express(优先队列Dijkstra)
Baoli1008
博客等级 码龄12年 70粉丝 293原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值