dfs深搜
凌晨四点的洛杉矶fly
这个作者很懒,什么都没留下…
展开
-
dfs 成语接龙
题目描述单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次),在两个单词相连时,其重合部分合为一部分,例如 beastbeast和astonishastonish,如果接成一条龙则变为beastonishbeastonish,另外相邻的两部分不能存在包含关系,例如atat 和 ati...原创 2018-11-24 09:34:35 · 279 阅读 · 0 评论 -
POJ 2034
DescriptionGiven a sequence of consecutive integers n,n+1,n+2,...,m, an anti-prime sequence is a rearrangement of these integers so that each adjacent pair of integers sums to a composite (non-prime...原创 2018-11-28 10:21:01 · 210 阅读 · 0 评论 -
dfs/bfs +二分
题意:n*n的矩阵,从左上到右下,找一条最大值见最小值最小的路,并输出该最小值。首先是用dfs做的: #include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=100+5;int n;int map[maxn][maxn]...原创 2018-11-28 11:15:43 · 148 阅读 · 0 评论 -
poj1207 拓扑排序+dfs
DescriptionOrder is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a partially ordered set in which every chain has an upper bound contains a maxima...原创 2018-12-03 22:32:23 · 187 阅读 · 0 评论 -
hdu1561树形dp+01背包
ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先攻克其他某一个特定的城堡。你能帮ACboy算出要获得尽量多的宝物应该攻克哪M个城堡吗? Input每个测试实例首先包括2个整数,N,M.(1 <= M <= N <= 200...原创 2019-01-23 20:56:04 · 152 阅读 · 0 评论 -
求树中两点距离的最大值(树的直径)
Given a tree (a connected graph with no cycles), you have to find the farthest nodes in the tree. The edges of the tree are weighted and undirected. That means you have to find two nodes in the tree w...原创 2019-01-15 21:50:54 · 1058 阅读 · 0 评论 -
poj1041
Little Johnny has got a new car. He decided to drive around the town to visit his friends. Johnny wanted to visit all his friends, but there was many of them. In each street he had one friend. He star...原创 2019-02-24 20:56:00 · 291 阅读 · 0 评论 -
/560/I(dfs+二分)
链接:https://ac.nowcoder.com/acm/contest/560/I来源:牛客网题目描述You have a tree with N nodes and N-1 edges. Each node has a weight. The i-th node's weight is Wi.Now you should dividethe N nodes into K...原创 2019-04-15 13:10:14 · 143 阅读 · 0 评论 -
2019河北省赛L题(dfs)
链接:https://ac.nowcoder.com/acm/contest/903/L来源:牛客网Icebound dreams of being aLegendary grandmaster. So he built a smart robot to help him.The robot works on a N*N matrix. All the numbers in the m...原创 2019-05-25 20:07:05 · 321 阅读 · 0 评论 -
牛客910/D(最大的湖)dfs
链接:https://ac.nowcoder.com/acm/contest/910/D来源:牛客网题目描述农场主约翰的农场在最近的一场风暴中被洪水淹没,这一事实只因他的奶牛极度害怕水的消息而恶化。然而,他的保险公司只会根据他农场最大的“湖”的大小来偿还他一笔钱。农场表示为一个矩形网格,有N(1≤N≤100)行和M(1≤M≤100)列。网格中的每个格子要么是干的,要...原创 2019-05-26 18:45:36 · 215 阅读 · 0 评论 -
dfs 从1-n取r个数的全排列
#include<bits/stdc++.h>using namespace std;int a[6000];int b[6000];int n,r;int tot;void print(){ tot++; for(int i=1;i<=r;i++) { cout<<a[i]<<" "; }...原创 2018-11-04 19:16:19 · 267 阅读 · 0 评论 -
poj 2362 dfs
题意: 给你M根长度可能不同的棍子,问你用着M根棍子能否拼成一个正方形. #include<iostream>#include<cmath>#include<cstring>#include<algorithm>using namespace std;int sum;int m;int a[30];int ...原创 2018-11-28 08:44:54 · 97 阅读 · 0 评论 -
dfs 数独
分析:int row[10][10];//row[i][x]=1表示第i行中数字x已经出现 int col[10][10];//col[i][x]=1表示第i列中数字x已经出现 int grid[10][10];//grid[i][x]=1表示第i个小棋盘中数字x已经出现. 然后假设当前网格坐标为(r,c),那么它对应于第几(k)个小...原创 2018-11-27 21:12:08 · 242 阅读 · 0 评论 -
HDU 4403 dfs
Problem DescriptionAoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He ...原创 2018-11-27 20:39:05 · 103 阅读 · 0 评论 -
dfs+bfs HDU 1044
Problem DescriptionIt is written in the Book of The Lady: After the Creation, the cruel god Moloch rebelled against the authority of Marduk the Creator.Moloch stole from Marduk the most powerful of ...原创 2018-11-25 18:57:33 · 202 阅读 · 0 评论 -
dfs 填充颜色
题目描述由数字00组成的方阵中,有一任意形状闭合圈,闭合圈由数字11构成,围圈时只走上下左右44个方向。现要求把闭合圈内的所有空间都填写成22.例如:6 \times 66×6的方阵(n=6n=6),涂色前和涂色后的方阵如下:0 0 0 0 0 00 0 1 1 1 10 1 1 2 2 11 1 2 2 2 11 2 2 2 2 11 1 1 1 1 10 0 0 0 ...原创 2018-11-24 23:25:50 · 160 阅读 · 0 评论 -
dfs HDU 1045
Problem DescriptionSuppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse...原创 2018-11-26 10:49:56 · 87 阅读 · 0 评论 -
dfs+剪枝 hdu1010
Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He re...原创 2018-11-26 11:15:05 · 103 阅读 · 0 评论 -
HDU 4536 dfs
XCOM-Enemy Unknown是一款很好玩很经典的策略游戏.在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3个国家攻击,作为联盟的指挥者,你要安排有限的联盟军去支援其中一个国家,抵抗进攻这个国家的外星人.战斗胜利之后这个被支援的国家恐慌值就会-2点(恐慌值最少减为1),而其他两个未被支援的国家恐慌...原创 2018-11-26 11:38:55 · 118 阅读 · 0 评论 -
POJ 2386
DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each squar...原创 2018-11-30 09:03:57 · 89 阅读 · 0 评论 -
poj1111 dfs
(L又是一道题意复杂的简单题)给你一个R*C的仅有字符’.’(表空格)和字符’X’(表物体)构成的棋盘,现在在给你一个坐标(从1计数),要你算出这个与这个坐标点相连的所有’X’构成物体的外表面周长. #include<cstdio>#include<cstring>using namespace std;const int maxn=30;int R,...原创 2018-11-26 21:52:02 · 118 阅读 · 0 评论 -
dfs
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to...原创 2018-11-30 09:31:33 · 91 阅读 · 0 评论 -
dfs 放苹果
Description把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。Input第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。Output对输入的每组数据M和N,用一行输出相应的K。Sample...原创 2018-11-30 11:22:58 · 173 阅读 · 0 评论 -
dfs HDU 1501
Problem DescriptionGiven three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrari...原创 2018-11-27 19:42:43 · 369 阅读 · 0 评论 -
C - Cat Snuke and a Voyage(dfs)
题目链接:https://atcoder.jp/contests/arc079/tasks/arc079_a题意:给你n个点m条边;问你是否存在一条从1到n的长度为2的边;代码:#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using...原创 2019-06-14 19:14:20 · 206 阅读 · 0 评论