
DFS&BFS
饮酒在风里
这个作者很懒,什么都没留下…
展开
-
新年好(最短路+dfs)
重庆城里有nn个车站,mm条双向公路连接其中的某些车站。每两个车站最多用一条公路连接,从任何一个车站出发都可以经过一条或者多条公路到达其他车站,但不同的路径需要花费的时间可能不同。在一条路径上花费的时间等于路径上所有公路需要的时间之和。佳佳的家在车站11,他有五个亲戚,分别住在车站a,b,c,d,ea,b,c,d,e。过年了,他需要从自己的家出发,拜访每个亲戚(顺序任...原创 2019-12-04 19:34:57 · 571 阅读 · 0 评论 -
P1434 [SHOI2002]滑雪——记忆化搜索
题目描述Michael喜欢滑雪。这并不奇怪,因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道在一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子:1 2 3 4 516 17 18 19 615 24 25 20 714...原创 2019-11-25 11:45:19 · 312 阅读 · 0 评论 -
二分图染色(DFS)
题目描述曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街。河蟹看到欢快的曹,感到不爽。河蟹决定封锁阳光大学,不让曹刷街。阳光大学的校园是一张由N个点构成的无向图,N个点之间由M条道路连接。每只河蟹可以对一个点进行封锁,当某个点被封锁后,与这个点相连的道路就被封锁了,曹就无法在与这些道路上刷街了。非常悲剧的一点是,河蟹是一种不和谐的生物,当两只河蟹封锁了相邻的两个点时,他...原创 2019-10-14 21:15:34 · 246 阅读 · 0 评论 -
图论-最小环问题(dfs+并查集)
题目描述有nn个同学(编号为11到nn)正在玩一个信息传递的游戏。在游戏里每人都有一个固定的信息传递对象,其中,编号为ii的同学的信息传递对象是编号为T_iTi的同学。游戏开始时,每人都只知道自己的生日。之后每一轮中,所有人会同时将自己当前所知的生日信息告诉各自的信息传递对象(注意:可能有人可以从若干人那里获取信息, 但是每人只会把信息告诉一个人,即自己的信息传递对象...原创 2019-10-14 13:30:45 · 638 阅读 · 0 评论 -
I - Fire Game FZU - 2150(双起点BFS)
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start...原创 2019-08-15 20:16:39 · 313 阅读 · 0 评论 -
Dungeon Master POJ - 2251 (BFS结构体+宽搜)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south...原创 2019-08-07 16:59:27 · 157 阅读 · 0 评论 -
棋盘问题 POJ - 1321 (深搜入门)
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n...原创 2019-08-07 14:54:31 · 204 阅读 · 0 评论 -
F - Prime Path POJ - 3126 (宽搜BFS)
F - Prime PathPOJ - 3126The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their of...原创 2019-08-13 20:37:51 · 118 阅读 · 0 评论 -
Prime Ring Problem Uva 524(回溯+深搜)
#include <iostream>#include <algorithm>#include <cstring>using namespace std;int n;int vis[21];int a[21];int judge(int a){ if(a<2) return 0; else {...原创 2019-01-14 15:58:24 · 144 阅读 · 0 评论 -
(剪枝+深搜)Tempter of the Bone
#include <iostream>#include <cstring>using namespace std;char a[10][10];int step;int b[4][2]={{-1,0},{1,0},{0,-1},{0,1}};int flag;int n,m,t;int g,l,ex,ey;void dfs(int x,int y,i...原创 2019-01-15 21:31:04 · 151 阅读 · 0 评论 -
PAT甲级L2-004 这是二叉搜索树吗? (25 分)(天梯赛备战)
#include <iostream>#include <vector>using namespace std;struct node{ int data; node *left,*right;};void insert(node* &root,int data)//生成二叉搜索树{ if(root==NULL) ...原创 2019-03-01 16:28:10 · 737 阅读 · 0 评论 -
L2-023 图着色问题 vector应用 C++
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <map>#include <vector>#include <set>using namespace std;vector<...原创 2019-03-27 21:50:30 · 162 阅读 · 0 评论 -
搜索入门-深搜(背包容量最大问题-减枝)
题目描述:有n件物品,背包容量为v,在选入背包的物品重量不超过容量v的前提下,让背包中物品的价值之和最大,求最大值。输入:5 8 3 5 1 2 2 4 5 2 1 3输出: 10#include <iostream>#include <algorithm>#include <cstring>#i...原创 2019-04-09 21:59:05 · 253 阅读 · 0 评论 -
搜索入门-深搜
给定N个整数,从中选择k个数,使得这k个数之和恰好等于一个给定整数的值,取平方和最大的组。输入:4 2 62 3 3 4输出:2 4#include <iostream>#include <algorithm>#include <cstring>#include <map>#include <cstdio>#i...原创 2019-04-09 22:41:02 · 134 阅读 · 0 评论 -
BFS宽搜模板(求矩阵中连通块的个数)
给出一个n×m的矩阵,元素为0或1.称每个位置的上下左右与之相邻。如果矩阵中有若干个1是相邻的,那么这些1就构成了一个块。求矩阵中“块”的个数。#include<iostream>#include<algorithm>#include<string>#include<string.h>#include <cstdio>#...原创 2019-04-15 22:56:41 · 1551 阅读 · 0 评论 -
搜索入门-广搜(模板)
一个N*M的迷宫,*代表墙,“.”代表空地,S是起点,T是终点。求从S到T的最短距离的步数,无法到达输出-1;#include <iostream>#include <queue>#include <cstdio>#include <cstring>using namespace std;const int maxn=100;s...原创 2019-04-17 20:37:31 · 794 阅读 · 0 评论 -
F. Graph Without Long Directed Paths(DFS图染色)
You are given a connected undirected graph consisting ofnnvertices andmmedges. There are no self-loops or multiple edges in the given graph.You have to direct its edges in such a way that the...原创 2019-05-10 14:17:36 · 212 阅读 · 0 评论