![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DFS
文章平均质量分 71
Zero_979
计算机科学与技术硕士在读
展开
-
LeetCode 热题 C++ 416. 分割等和子集 437. 路径总和 III 438. 找到字符串中所有字母异位词 448. 找到所有数组中消失的数字 461. 汉明距离 494. 目标和
给你一个的数组nums。请你判断是否可以将这个数组分割成两个子集,使得两个子集的元素和相等。true数组可以分割成 [1, 5, 5] 和 [11]。false数组不能分割成两个元素和相等的子集。原创 2023-03-07 11:04:22 · 126 阅读 · 0 评论 -
LeetCode 热题 C++ 200. 岛屿数量 206. 反转链表 207. 课程表 208. 实现 Trie (前缀树)
给你一个由'1'(陆地)和'0'(水)组成的的二维网格,请你计算网格中岛屿的数量。岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。此外,你可以假设该网格的四条边均被水包围。原创 2023-02-27 13:34:31 · 325 阅读 · 0 评论 -
LeetCode 热题 C++ 79. 单词搜索
给定一个m x n二维字符网格board和一个字符串单词word。如果word存在于网格中,返回true;否则,返回false。单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。遇到的坑:一开始每次用的是减少字符串,用substr的,但是这样会超时。所以再增加一个变量k,每次要比较的就是word[k]和当前字母。原创 2022-11-22 19:57:01 · 294 阅读 · 0 评论 -
LeetCode 热题 C++ 78. 子集
给你一个整数数组nums,数组中的元素。返回该数组所有可能的子集(幂集)。解集包含重复的子集。你可以按返回解集。原创 2022-11-21 20:46:50 · 192 阅读 · 0 评论 -
LeetCode 热题 C++ 39. 组合总和
给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。candidates 中的 同一个 数字可以 无限制重复被选取。如果至少一个数字的被选数量不同,则两种组合是不同的。对于给定的输入,保证和为 target 的不同组合数少于 150 个。示例 1:输入:candidates = [2,3,6,7], target = 7。原创 2022-11-02 22:59:52 · 157 阅读 · 0 评论 -
LeetCode 热题 17. 电话号码的字母组合 19.删除链表的倒数第 n 个结点 20. 有效的括号
递归思路:遍历第一个字符串,每加入一个字母后开始递归下一个字符串,递归完后弹出这个字母。递归终止条件:当遍历到了最后一个字符串,就把生成的字符串加入到动态数组中,并结束该轮递归。分析一下题目,很好掌握规律。因为前后都是有顺序的,并且第一个的第一个字母对应第二个全部执行完,再执行第一个的第二个字母,这时候我们就可以想到用递归来解决。用t和p两个指针,t走到n后p再往后走,这样等到t走完的时候,p就是倒数第n个点了。看代码应该很容易看懂()删除的话就直接看代码吧。原创 2022-09-21 13:36:57 · 87 阅读 · 0 评论 -
POJ - 1088 滑雪
题目地址:https://vjudge.net/problem/16378/origin题目:It's not surprising that Wanggann likes skiing, because skiing is really exciting. However, in order to gain speed, the sliding area must be tilted d...原创 2018-08-09 16:46:18 · 176 阅读 · 0 评论 -
UVA - 1354 Mobile Computing【这是我写过最认真的题解】 C++
题目:https://odzkskevi.qnssl.com/57f8af2fae951ced8a717f7384d90ed8?v=1532560185题目大意:(准备六级的我决定练一练英语阅读,所以翻译一下)这里有一个神秘的星球叫Yaen,它的空间只有两个维度。这里有很多漂亮的石头在这个星球上,Yaen星人喜欢捡这些石头。他们把这些石头带回家,用很棒的移动装置来装饰他们的二维房间。...原创 2018-07-27 16:32:52 · 313 阅读 · 0 评论 -
UVA - 129 Krypton Factor C++
题目:https://odzkskevi.qnssl.com/cec524ae62aa641d4fa8a9936d0f3b4a?v=1531960847思路:输出每四个空一格,没16个换一行!代码:#include<iostream>#include<cstring>#include<string>#include<cstdio&g...原创 2018-07-25 16:43:44 · 250 阅读 · 0 评论 -
八皇后问题C++
思路见紫书= =在这基础上增加了一个输出函数。记得vis的数组一定要开的稍微大一些。毕竟8+8=16.代码:#include<iostream>#include<cstring>#include<cstdio>using namespace std;int vis[3][20];int C[10],tot;void print(){...原创 2018-07-25 12:31:57 · 182 阅读 · 0 评论 -
UVA - 10305 C - Ordering Tasks C++
题目:John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed.InputThe input will consist of several ...原创 2018-05-22 20:31:33 · 331 阅读 · 0 评论 -
H - 8 C++(有bug)
题目:On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is m...原创 2018-04-09 21:29:23 · 179 阅读 · 0 评论 -
L - 12 C++
题目:A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number o...原创 2018-04-08 21:29:13 · 160 阅读 · 0 评论 -
K - 11 C++
题目:The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides...原创 2018-04-08 21:27:27 · 188 阅读 · 0 评论 -
J - 10 C++
题目:A while ago I had trouble sleeping. I used to lie awake, staring at the ceiling, for hours and hours. Then one day my grandmother suggested I tried counting sheep after I'd gone to bed. As always w...原创 2018-04-08 21:26:07 · 121 阅读 · 0 评论 -
I - 9
题目:呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体. Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,...原创 2018-04-08 21:22:54 · 95 阅读 · 0 评论 -
F - 6 C++
题目:Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in o...原创 2018-04-08 21:19:37 · 127 阅读 · 0 评论 -
D - 哈密顿绕行世界问题
题目:一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. Output输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第几...原创 2018-04-08 21:16:15 · 163 阅读 · 0 评论 -
M - 13 C++
题目:The 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 realized that the bo...原创 2018-04-08 21:14:30 · 214 阅读 · 0 评论