
DFS
junior19
abcde
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
剑指offer:二叉搜索树与双向链表
题目描述输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。思路:模拟中序遍历的过程就OK,或者利用分治的思想,递归分别处理左右子树,再合并左右子树成一条链。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right;...原创 2019-02-09 19:20:31 · 327 阅读 · 0 评论 -
HDU5167:Fibonacci(dfs)
FibonacciTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 43 Accepted Submission(s): 8Problem DescriptionWe consider the Fibon原创 2017-07-17 22:08:22 · 555 阅读 · 0 评论 -
HDU5696:区间的价值(搜索 & 分治 & 思维)
区间的价值Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1366 Accepted Submission(s): 608Problem Description我们定义“区间的价值”为一段区间的最大值原创 2017-11-16 00:09:58 · 605 阅读 · 0 评论 -
HDU5527:Too Rich(DFS & 贪心 & 思维)
Too RichTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1613 Accepted Submission(s): 413Problem DescriptionYou are a rich p原创 2017-11-14 15:53:40 · 690 阅读 · 0 评论 -
HDU5285:wyh2000 and pupil(二分图染色 & 贪心)
wyh2000 and pupilTime Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1824 Accepted Submission(s): 599Problem DescriptionYoung th原创 2017-11-17 22:06:04 · 300 阅读 · 0 评论 -
HihoCoder 1224:Racing(树DFS & 贪心)
There is a racing track in Gensokyo.The racing track is a directed tree with n nodes in which the direction of each are from the father to the son.Yuuka wants to pick a longest path in the tree bu原创 2017-10-18 21:18:23 · 219 阅读 · 0 评论 -
HDU5925:Coconuts(二维坐标离散化 + DFS)
CoconutsTime Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1206 Accepted Submission(s): 368Problem DescriptionTanBig, a friend o原创 2017-09-27 11:46:45 · 516 阅读 · 0 评论 -
CodeChef:Chef and Subsequences(思维 & dfs)
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and pas原创 2017-09-15 21:41:33 · 295 阅读 · 0 评论 -
HDU1530:Maximum Clique(最大团)
Maximum CliqueTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4546 Accepted Submission(s): 2392Problem DescriptionGiven a g原创 2017-08-06 22:25:09 · 446 阅读 · 0 评论 -
CF510B:Fox And Two Dots(dfs)
B. Fox And Two Dotstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFox Ciel is playing a mobile puzzle gam原创 2017-08-04 14:30:39 · 274 阅读 · 0 评论 -
POJ1351:Number of Locks(记忆化搜索)
Number of LocksTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1434 Accepted: 697DescriptionIn certain factory a kind of spring locks is manufactured.原创 2017-11-24 18:49:12 · 332 阅读 · 0 评论 -
POJ2192:Zipper(记忆化搜索)
ZipperTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 18818 Accepted: 6716DescriptionGiven three strings, you are to determine whether the third strin原创 2017-11-24 23:22:38 · 215 阅读 · 0 评论 -
CFgym:Sky Tax(DFS序 & 树)
题意:给N个节点的最小生成树,Q个询问,初始首都为R节点,1 ≤ N ≤ 100 000, 1 ≤ Q ≤ 50 000,1 ≤ R ≤ N, 每个询问包含两个数S和U,0 ≤ S ≤ 1,1 ≤ U ≤ N,S为0代表将首都更新为U节点,否则,请计算出有多少个节点必须经过U才能到达首都。思路:先DFS一次记录DFS序和每个节点到根节点的距离和每个节点的祖先节点,那么当首都为U的子树节点时,答原创 2017-07-12 18:12:05 · 2269 阅读 · 0 评论 -
HDU3966:Aragorn's Story(树链剖分)
Aragorn's StoryTime Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18159 Accepted Submission(s): 4792 Problem DescriptionOur protagonist...原创 2018-10-31 15:37:01 · 217 阅读 · 0 评论 -
SPOJ:Another Longest Increasing Subsequence Problem(CDQ分治 + 最长上升子序列)
LIS2 - Another Longest Increasing Subsequence Problemno tags Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it.An increasing sequence A1..An...原创 2018-08-21 20:13:22 · 722 阅读 · 0 评论 -
BZOJ3262:陌上花开(CDQ分治 + BIT)
Description有n朵花,每朵花有三个属性:花形(s)、颜色(c)、气味(m),用三个整数表示。现在要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量。定义一朵花A比另一朵花B要美丽,当且仅Sa>=Sb,Ca>=Cb,Ma>=Mb。显然,两朵花可能有同样的属性。需要统计出评出每个等级的花的数量。Input第一行为N,K (1 <= N ...原创 2018-08-19 22:31:14 · 301 阅读 · 0 评论 -
GYM:Jakanda Forever(LCA + BIT)
J. Jakanda Forevertime limit per test2.0 smemory limit per test256 MBinputstandard inputoutputstandard outputIn East Hackerland, there is a country called Jakanda which possesses highly advanced techn...原创 2018-07-06 17:25:52 · 410 阅读 · 0 评论 -
CSU1811:Tree Intersection(树启发式合并)
Bobo has a tree with n vertices numbered by 1,2,…,n and (n-1) edges. The i-th vertex has color c i, and the i-th edge connects vertices a i and b i.Let C(x,y) denotes the set of colors in subtree root...原创 2018-04-27 23:10:34 · 378 阅读 · 0 评论 -
ZOJ3378:Attack the NEET Princess (边双连通分量)
Houraisan Kaguya (蓬萊山輝夜) is the NEET (not in education, employment or training) princess living in Eientei (永遠亭). She is an unemployed geek, who sits at home and surfs the Internet all day. But today ...原创 2018-03-24 10:01:24 · 320 阅读 · 0 评论 -
51nod:公共祖先(主席树 & DFS序)
有一个庞大的家族,共n人。已知这n个人的祖辈关系正好形成树形结构(即父亲向儿子连边)。在另一个未知的平行宇宙,这n人的祖辈关系仍然是树形结构,但他们相互之间的关系却完全不同了,原来的祖先可能变成了后代,后代变成的同辈……两个人的亲密度定义为在这两个平行宇宙有多少人一直是他们的公共祖先。整个家族的亲密度定义为任意两个人亲密度的总和。Input第一行一个数n(1<=n<=100000)接...原创 2018-03-05 23:23:24 · 294 阅读 · 0 评论 -
CF592D:Super M(树的直径 & 虚树)
题意:给一棵树,标记其中M个点,找一条路径通过这M个点且路程要最小,若有多个答案取起点最小的那条路径(输出:起点和路程)。 首先假如起点为s" role="presentation">sss,终点为t" role="presentation">ttt,总路程就是2m−dist(s,t)" role="presentation">2m−dist(s,t)2m−dist(s,t)2m-原创 2018-01-20 15:18:50 · 418 阅读 · 0 评论 -
BZOJ1064:假面舞会(DFS & 思维)
1064: [Noi2008]假面舞会Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2264 Solved: 1094[Submit][Status][Discuss]Description一年一度的假面舞会又开始了,栋栋也兴致勃勃的参加了今年的舞会。今年的面具都是主办方特别定制的。每个参加舞会的人都可以在入场时选择一 个原创 2017-12-06 19:39:49 · 368 阅读 · 0 评论 -
CF804D:Expected diameter of a tree(树的直径 & dfs)
D. Expected diameter of a treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha is a good student and原创 2017-07-26 20:18:58 · 612 阅读 · 0 评论 -
HDU1016:Prime Ring Problem(dfs)
Prime Ring ProblemTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 52756 Accepted Submission(s): 23320Problem DescriptionA rin原创 2017-08-03 20:47:11 · 231 阅读 · 0 评论 -
CF758E:Broken Tree(DFS & 思维)
E. Broken Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree that has n vertices, wh原创 2017-08-02 11:25:48 · 547 阅读 · 0 评论 -
AtCoder:Hamiltonish Path(思维 & dfs)
B - Hamiltonish PathTime limit : 2sec / Memory limit : 256MBScore : 500 pointsProblem StatementYou are given a connected undirected simple graph, which has N vertices and M edges原创 2017-05-13 18:39:02 · 658 阅读 · 0 评论 -
AOJ0525:Osenbei(DFS + Bitset)
問題IOI製菓では,創業以来の伝統の製法で煎餅(せんべい)を焼いている.この伝統の製法は,炭火で一定時間表側を焼き,表側が焼けると裏返して,炭火で一定時間裏側を焼くというものである.この伝統を守りつつ,煎餅を機械で焼いている.この機械は縦 R (1 ≤ R ≤ 10) 行, 横 C (1 ≤ C ≤ 10000) 列の長方形状に煎餅を並べて焼く.通常は自動運転で,表側が焼けたら一斉に煎原创 2017-04-08 19:59:32 · 319 阅读 · 0 评论 -
hihoCoder1041:国庆出游(bitset引导dfs遍历)
#1041 : 国庆出游时间限制:1000ms单点时限:1000ms内存限制:256MB描述小Hi和小Ho准备国庆期间去A国旅游。A国的城际交通比较有特色:它共有n座城市(编号1-n);城市之间恰好有n-1条公路相连,形成一个树形公路网。小Hi计划从A国首都(1号城市)出发,自驾遍历所有城市,并且经过每一条公路恰好两次——来回各一次——这原创 2017-03-04 21:49:23 · 1174 阅读 · 0 评论 -
CF:The Fault in Our Cubes(DFS)
A. The Fault in Our Cubestime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRula is the Human Resources Man原创 2017-02-25 16:49:32 · 248 阅读 · 0 评论 -
HDU1572:下沙小面的(2)(DFS)
下沙小面的(2)Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2309 Accepted Submission(s): 1010Problem Description前文再续,书接上一题。话说当上小面原创 2017-03-03 21:55:10 · 248 阅读 · 0 评论 -
CF6B: President's Office(简单DFS)
B. President's Officetime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputPresident of Berland has a very vast o原创 2017-01-30 20:05:47 · 558 阅读 · 0 评论 -
HDU4403:A very hard Aoshu problem(DFS暴搜)
detail:http://blog.youkuaiyun.com/sr_19930829/article/details/39206145?utm_source=tuicool&utm_medium=referralA very hard Aoshu problemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3276原创 2017-01-30 17:47:50 · 262 阅读 · 0 评论 -
HDU4707:Pet(DFS求树深)
233333333333333 PetTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2762 Accepted Submission(s): 1362Problem Descrip原创 2017-03-02 12:39:32 · 340 阅读 · 0 评论 -
NYOJ32:组合数(DFS入门)
组合数时间限制:3000 ms | 内存限制:65535 KB难度:3描述找出从自然数1、2、... 、n(0<n<10)中任取r(0<r<=n)个数的所有组合。输入输入n、r。输出按特定顺序输出所有组合。特定顺序:每一个组合中的值从大到小排列,组合之间按逆字典序排列。样例输入5 3样例输出543542541532原创 2017-01-16 00:49:56 · 236 阅读 · 0 评论 -
CFgym:Digits Permutation(DFS)
题意:给一个数字n,允许调换各数位的位置,但不允许有前导零,问能否组成能被17整除的数。思路:深搜构造出所有数字即可,优化的地方就是同一个位置的数字枚举一次就行了,避免重复。# include using namespace std;char s[20], t[20], len;bool flag;int vis[20];bool judge(char *t){ in原创 2017-05-16 13:46:25 · 285 阅读 · 0 评论 -
POJ1655:Balancing Act(树的重心 DFS)
Balancing ActTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13440 Accepted: 5658DescriptionConsider a tree T with N (1 <= N <= 20,000) nodes numbered原创 2017-04-26 16:36:04 · 259 阅读 · 0 评论 -
CF793B:B Igor and his way to work(DFS & BFS)
B. Igor and his way to worktime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWoken up by the alarm clock Igo原创 2017-05-29 14:18:54 · 430 阅读 · 0 评论 -
CF734E:Anton and Tree(缩点 & 直径)
E. Anton and Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnton is growing a tree in his garden. In原创 2017-08-01 21:19:29 · 514 阅读 · 0 评论 -
CFgym:Good morning!(dfs)
For an example input:318083132a possible correct answer is:18080133题意:如图键盘,只能向下或向右或原地按,T组数据,给出N,1思路:dfs构造所有数字存下,二分搜索即可。# include using namespace std;int m[6][6]={{-1,-1,-1,-1原创 2017-07-19 16:29:34 · 311 阅读 · 0 评论 -
CFgym:Old Chess Sets(dfs 循环)
题意:N张桌,M个人,每张桌子有两张牌,一张向上一张向下,M个人初始各自坐在某张桌子前,每1min执行一次操作:看一眼当前桌子的反牌,走到该牌对应的向上的桌子处。问每个人经过特定的时间后在哪个桌子前。思路:简单深搜,找循环节,记录房间处在循环的哪个位置,最后加上时间取模一下即可。# include # define pb push_backusing namespace std;co原创 2017-07-30 20:25:05 · 283 阅读 · 0 评论