一道题两种解法:深度优先搜索、广度优先搜索-AtCode ABC204 C - Tour

用Arduino Uno和纸板做个扫地机器人?手把手教你复刻一个低成本DIY方案(附完整代码) 本文详细介绍了如何用Arduino Uno和纸板制作一款低成本DIY扫地机器人,涵盖材料准备、机械结构设计、电路系统搭建和智能清扫算法实现。通过开源硬件和日常废弃物,打造极致性价比的创客项目,适合初学者学习电子和编程。 阅读详情

标签

  • DFS、BFS

题目地址

C - Tour

  • https://atcoder.jp/contests/abc204/editorial/1991

問題描述

The republic of AtCoder has N cities numbered 1 through N and Mroads numbered 1 through M.

Road i leads from City Ai_ii​ to City Bi_ii​, but you cannot use it to get from City Bi_ii​ to City Ai_ii​.

Puma is planning her journey where she starts at some city, travels along zero or more roads, and finishes at some city.

How many pairs of cities can be the origin and destination of Puma’s journey? We distinguish pairs with the same set of cities in different orders.

Constraints

  • 2 ≤\leq≤ N ≤\leq≤ 2000
  • 0 ≤\leq≤ M ≤\leq≤ min⁡\minmin(2000,N(N-1))
  • 1 ≤\leq≤ Ai_ii​,Bi_ii​ ≤\leq≤ N
  • Ai_ii​ ≠\neq​= Bi_ii​
  • (Ai_ii​,Bi_ii​) are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A1 B1
...
AM BM

Output

Print the answer.


Sample Input 1

3 3
1 2
2 3
3 2

Sample Output 1

7

We have seven pairs of cities that can be the origin and destination: (1,1),(1,2),(1,3),(2,2),(2,3),(3,2),(3,3).


Sample Input 2

3 0

Sample Output 2

3

We have three pairs of cities that can be the origin and destination: (1,1),(2,2),(3,3).


Sample Input 3

4 4
1 2
2 3
3 4
4 1

Sample Output 3

16

Every pair of cities can be the origin and destination.

题意

AtCoder王国有

  • N个编号为1到N的城市
  • M条编号为1到M的道路。

道路i从Ai_ii​市通往Bi_ii​市,但不能能用从Bi_ii​市通往Ai_ii​市。

彪马正在计划她的旅程,她从某个城市出发,沿着零条或多条道路旅行,然后在某个城市结束。

求有多少种起点和终点城市组合?

思路

  • 固定起始点,然后遍历到达可能的城市
  • 可以考虑使用DFS、BFS算法遍历

题解

小码匠: DFS

int n;
vector<bool>leaf(n);

void dfs(int x, vector<vector<int>> &vvi) {
    if(leaf[x]) {
        return;
    }
    leaf[x] = true;
    for(auto a : vvi[x]) {
        dfs(a, vvi);
    }
}

void coder_solution() {
    // 提升cin、cout效率
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int m, temp = 0;
    cin >> n >> m;
    vector<vector<int>> vvi(n);
    int a, b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        vvi[a - 1].push_back(b - 1);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            leaf[j] = false;
        }
        dfs(i, vvi);
        for (int j = 0; j < n; j++) {
            if (leaf[j]) {
                temp++;
            }
        }
    }
}

小码匠: BFS

void best_solution() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int a, b;
    vector<vector<int>> vvi(n);
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        vvi[a - 1].push_back(b - 1);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    dist[0] = 0;
    int v;
    int j = 0;
    for(int i = 0; i < n; i++) {
        que.push(i);
        dist[i] = 0;
        while(!que.empty()) {
            v = que.front();
            que.pop();
            for(auto next_v : vvi[v]) {
                if (dist[next_v] != -1) {
                    continue;
                }
                dist[next_v] = dist[v] + 1;
                que.push(next_v);
            }
        }
        j += n - count(dist.begin(), dist.end(), -1);
        dist.assign(n, -1);
    }
    cout << j;
}

官方题解1:BFS

  • 一些语法感觉有些诡异,例如第8行,第14行的循环语句,老码农建议不要学,不符合多数人习惯
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    auto e = vector(n, vector<int>());
    for(int i{}, a, b; i < (m); ++i){
        cin >> a >> b;
        --a, --b;
        e[a].push_back(b);
    }
    ll ans{};
    for(int s{}; s< (n); ++s){
        vector<bool> vis(n);
        vis[s] = true;
        queue<int> q;
        q.push(s);
        while(!q.empty()){
            ++ans;
            int i = q.front();
            q.pop();
            for(auto&j:e[i]) if(!vis[j]){
                vis[j] = true;
                q.push(j);
            }
        }
    }
    cout << ans << endl;
}

官方题解2:DFS

#include<bits/stdc++.h>

using namespace std;
const int MAX_N = 2000;
vector<vector<int>> G;
bool temp[MAX_N];

void dfs(int v) {
    if (temp[v]) {
        return;
    }
    temp[v] = true;
    for (auto vv: G[v]){
        dfs(vv);
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    G.resize(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            temp[j] = false;
        }
        dfs(i);
        for (int j = 0; j < N; j++) {
            if (temp[j]){
                ans++;
            |
        }
    }
    cout << ans;
}

复盘

  • 动态数组初始化

    dist.assign(n, -1);
    
生存曲线绘制及图例标签添加(使用R语言) 数据应该包含两列:一个是表示个体生存时间的时间变量(通常称为"时间(time)“)和一个是表示个体是否发生事件(如死亡)的事件变量(通常称为"事件(event)”)。通过修改上述代码中的数据和参数,您可以根据自己的需求绘制生存曲线,并添加相应的图例信息和标签。生存曲线是在生存分析中常用的工具,用于描述一组个体随时间的存活概率。函数的第一个参数指定图例的位置,这里我们选择了右上角(“topright”)。包来进行生存曲线的绘制,并通过添加图例信息和标签来增强可视化效果。的数据框,包含这两列数据。 阅读详情

相关推荐

深入浅出CenterFusion

结合论文和代码理解CenterFusion

Untitled的专栏 5104

AtCoder - ABC 270 - C(DFS+树上路径查询)

先跑一遍DFS求出每个节点的深度后,对于求结点 a,b 的路径,我们需要维护两个数组vector,数组 v1,v2 分别存从节点 a,b 开始的路径;fa[],要求的节点x到节点 y 的路径,就是从节点 x 一直向父节点遍历输出直到节点 y 即可。给定一棵有 N 个节点的树和两个节点 x,y ,按顺序输出从节点 x 到节点 y 的路径。拼接数组中所存的节点,顺序输出数组 v1 ,再输出两路径相遇处的节点 t ,最后。2. dfs预处理树中节点的深度,预处理以某一节点为根节点的所有节点的父节点。

m0_64172681的博客 821

STM32F4_LCD显示汉字

LCD显示汉字和显示图片、数字、字符的原理是一样的,都是将汉字、图片、数字以及字符转换点阵,进而通过函数扫描点阵在LCD上显示;

light_2025的博客 1万+

AtCoder Beginner Contest 204 赛后补题

E - Rush Hour 2 题目链接:https://atcoder.jp/contests/abc204/tasks/abc204_e 题意 给定一张无向图,一个人时刻ttt从一个点走到另一个点需要使用Ci+⌊Dit+1⌋C_i + \lfloor \frac{D_i}{t + 1} \rfloorCi​+⌊t+1Di​​⌋的时间。起点是1号点,终点是n号点,起始时刻是0,可以在某一点等待任意秒后再出发。求从起点到终点的最短时间。 思路 设到达uuu点的时刻为ttt,下一个点是vvv,设在u点等待了x

qq_45834992的博客 971

全新YOLOv11一文弄懂 | YOLOv11网络结构解读 、yolov11.yaml配置文件详细解读与说明、模型训练参数详细解析 | 通俗易懂!入门必看系列!

本文全面介绍了YOLOv11目标检测算法,包含网络结构解析、yaml配置文件详解及训练教程。YOLOv11通过改进的C3k2f模块、SPPF和C2PSA注意力机制等创新设计,在COCO数据集上实现了比YOLOv8更优的性能。文章详细解读了yolov11.yaml配置文件的参数设置、主干网络(backbone)和头部网络(head)结构,并提供了完整的训练代码示例和参数说明。训练部分涵盖了模型选择、参数设置及优化技巧,包括epochs、batch size、学习率等关键参数的调整建议。最后总结了YOLOv11

Ai缝合怪、助力小伙伴高效发论文 3万+

Open3D 从体素网格构建八叉树【2025最新版】

从体素网格构建八叉树,博客长期更新,本文最近更新时间为:2025年1月1日。

点云侠的博客 34万+

AtCoder Beginner Contest 192 E.Train

AtCoder Beginner Contest 192 E.Train 题目链接 Problem Statement In the Republic of AtCoder, there are N cities numbered 1 through N and M railroads numbered 1 through M. Railroad i connects City AiA_iAi​ and City BiB_iBi​ bidirectionally. At time 0, KiK_iKi​,

旺崽的博客 2268

【雕爷学编程】Arduino动手做(45)---红外光电避障传感器模块4

雕爷学编程,Arduino动手做,开源硬件,创客传感器,红外光电避障传感器模块

雕爷学编程 2503

AtCoder Beginner Contest 204 A~E 题解

ABC204 A~E 题解 A - Rock-paper-scissors B - Nuts C - Tour D - Cooking E - Rush Hour 2

天生我材必有用,千金散尽还复来。 9700

华为OD机试真题 新系统2026-04-01 Python&JS【计算数列位置N的值】

如果其前面的M个元素中,存在值相同的元素,则该位置上的数值等于前面M个数中最大的数值与最小的数值之如果其前面的M个元素中,不存在值相同的元素,则该位置上的数值等于前面M个数中最大的数值与最小的数值之差;1、输入M、N两个数,则按照以下规则形成一个数列;两个整数,用逗号分割,分别表示M和N。一个整数,表示数列第N个位置上的数值。2、数列的前M个元素的值为1到M;请计算该数列第N个位置上的数值。N取值范围:1<= N<=50。M取值范围:3<=M<=10。

MISAYAONE的博客 3222

YOLO26 实例分割技术:Mask 分支与特征融合

YOLO26实例分割技术研究摘要:本文提出了一种基于YOLO架构的高效实例分割方法,通过创新设计Mask分支和特征融合策略解决像素级分割精度、多尺度目标处理等挑战。系统采用共享Backbone提取特征,检测分支输出边界框和类别,Mask分支生成原型Mask和组合系数。核心创新包括:1)原型Mask生成与线性组合机制;2)检测与Mask特征共享;3)结合BCE和Dice的多任务损失函数。实验表明该方法在保持实时性的同时实现了高质量分割,为轻量级实例分割提供了新思路。

一键难忘的博客 248

AtCoder Beginner Contest 204(补题)

C - Tour 题意: 给个有向图,问你有多少对点,可以作为起点和终点,作为起点和终点,意味着可以从起点到终点。 思路: 直接从每个点 dfs一遍,看能到达的点有多少个,直接加起来即可。 #include<bits/stdc++.h> using namespace std; const int N=2010; int e[N],h[N],ne[N],idx; int n,m; bool st[N]; void add(int a,int b) { e[idx]=b,ne[idx]=

weixin_54699118的博客 710

【JDK】win 10 / win 11:jdk 8 下载、安装、配置、验证

win10 / win 11:JDK 最新版本下载 / 历史版本下载(jdk 8)、安装、配置系统环境变量、验证安装全详细操作教程

顾三殇 —— 博客空间(软件测试) 13万+

AtCoder Beginner Contest 204

AtCoder Beginner Contest 204

青少年趣味编程 1015

lwip-2.0.3

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

AtCoder - ABC 165 - F(DFS树) | 163 - F(容斥原理 + DFS树)

DFS树的两道题,后一道待再补补。

m0_64172681的博客 533

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

AtCoder - ABC 166 - F(DFS / 贪心)

题意:共操作 N 次,每次输入的是字符串。问能否在保证三个数都非负的条件下进行 n 次操作,如果可以输出Yes以及每次操作进行加1的那个字母;如果不能输出No。

m0_64172681的博客 432

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

【ATcoder】【DFS | 哈希 +并查集 | BFS 】Alternating Path

题目链接: 题意: 这个题目的意思是:给定一个h*w的方格内,只有' . ' 和 ' # ' 两个符号, 请问有多少条路径是  ' . '   ------&gt;  ' # '  ,其中路径中必须是 ' . ' 和 ’ # ‘ 相间。 小结: 这个题真的不会做,我当时就懵逼了,啥都不知道,然后看了网友的做法,发现原来就是找联通块,只要找到联通块就行了,这个答案就是: ans=每个联通...

Z_sea的博客 492

AtCoder - ABC 326 - D - ABC Puzzle (DFS)

看了很多题解都是写了一大坨,看起来非常的混乱,然而自己去写的时候又不可避免的写了一坨,只能尽可能的去优化代码可读性。

2302_79440616的博客 1839

AtCoder Beginner Contest 231 E 贪心 DFS 记忆化搜索

题目 有N种货币,每种对应ai元,a1一定等于1,且ai-1一定是ai的倍数。 求出完成一笔X元的交易所需的最小货币数。 即支付钱加找钱所需的货币数加起来最小。 题解思路 贪心策略 用这个付完,即不找零。 要么用这个多付钱(前提是本来有多,否则就是白费的搜索)然后求最小的找零数。 在这两种情况中取min 因为a是从1开始的,所以必然能取到数。 这题复杂度一言难尽,居然能这么暴力。 AC代码 #include <bits/stdc++.h> //#include <unordered_map

从你的全世界路过 525

atcoder Low Range-Sum Matrix dfs

问题 F: Low Range-Sum Matrix 时间限制:1 Sec内存限制:128 MB 提交:83解决:9 [提交] [状态] [命题人:admin] 题目描述 You received a card at a banquet. On the card, a matrix of N rows and M columns and two integers K and ...

喵喵喵 380

AtCoder abc320 D,题解居然敢用 DFS?

使用 DFS,在本地电脑上运行,直接堆栈溢出。就容易爆栈,它居然敢用。

qq_36224021的博客 286

AtCoder 3596 C - Bridge_DFS

AtCoder 3596 C - Bridge Problem Statement 连通的定义是:图中的任意两个点之间能互相到达。 给你一个包含n个点,m条边的无向图.如果去掉某条边之后,该图不连通了.那么这条边称为“special edge”.输出"special edge"的个数.Input第一行两个整数n,m(n<=50,m<=min(n*(n-1))/2,50).接下来m行...

weixin_30414635的博客 472

【AtCoder - abc311_d】Grid Ice Floor【DFS】

显然搜索题,但是范围是两百,不能每个点都递归,参照之前的题,会出现一些能递归的关键点。我们先对于每个点上下左右走到头,求出每个点对应的下一个关键点,然后从起点开始递归,对于每个点记录有没有“走过”,和有没有递归过,然后到达每个点都去找关键点就行。

ssllyr 393

AtCoder Beginner Contest 165 C.Many Requirements

AtCoder Beginner Contest 165 C.Many Requirements 题目链接 很多人看到题目就懵了,我个人感觉这题位置不好,比D要难一点????,我说的难是指难想一点~ 一开始大家肯定比较懵,看来半天读懂了题目意思,但是却想不到最优解法,我们不妨观察一下 N,MN,MN,M 的范围,立马想到了暴力,没错,我们就暴力列举所有 A 可能的排列情况即可,用到了 DFSDFSDF...

旺崽的博客 2709

AtCoder abc_264 C - Matrix Reducing(嵌套 dfs)

嵌套 dfs

Jacob0824的博客 1074

atcoder 167 C(dfs)

题目传送门 文章目录思路:废话: 思路: 这道题范围比较小,直接暴力搜索就行(可是本蒟弱,比赛时没做出来。。。) 对于每一本书要么买,要么不买,递归遍历n本书 开始没理解到这个dfs怎么设计。。。 参考:大佬文章 #include <iostream> #include<algorithm> using namespace std; const int maxn = 20; int a[maxn][maxn]; int ans = 1e9; int n,m,x; int Get[m

qq_45769627的博客 400
上一篇: 一文全面了解PostgreSQL常用命令
下一篇: 动态规划基础题(第1题):被变换的菲波那切数列
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小码匠和老码农

喜欢作者

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值