随笔分类 -  02.搜索 - (2)DFS

摘要:题目: 输入一个字符串,打印出该字符串中字符的所有排列。 你可以以任意顺序返回这个字符串数组,但里面不能有重复元素。 思路: 一个很直观的思路,对于任意一个字符串,例如"abcde",我首先枚举选定首字符,例如先选定了首字符是"a",那剩下部分的怎么permutation的事情就交给函数permut 阅读全文
posted @ 2021-06-22 17:33 Dilthey 阅读(88) 评论(0) 推荐(0)
摘要:题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 题解: 可以证明,$1 \sim N$ 中最大的反质数,就是 $1 \sim N$ 中约数个数最多的数中,最小的那个。 证明:假设 $1 \sim N$ 中最大的反质数 $x$ 不是 阅读全文
posted @ 2019-04-08 23:28 Dilthey 阅读(242) 评论(0) 推荐(0)
摘要:题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS。 DFS思路:从目前 $x[1 \sim p]$ 中选取两个,作为一个新的值尝试放入 $x[p+1]$。 迭代加深思路:设定一个深度限制,一旦到达这个界限,即继续往下搜索;该深度限制 阅读全文
posted @ 2019-04-02 22:44 Dilthey 阅读(297) 评论(0) 推荐(0)
摘要:题目链接:传送门 描述 作为惩罚,GY被遣送去帮助某神牛给女生送礼物(GY:貌似是个好差事)但是在GY看到礼物之后,他就不这么认为了。某神牛有N个礼物,且异常沉重,但是GY的力气也异常的大(-_-b),他一次可以搬动重量和在w(w<=2^31-1)以下的任意多个物品。GY希望一次搬掉尽量重的一些物品 阅读全文
posted @ 2019-04-02 21:14 Dilthey 阅读(217) 评论(0) 推荐(0)
摘要:题目链接:https://codeforces.com/problemset/problem/570/D 题解: 这种题,基本上容易想到DFS序。 然后,我们如果再把所有节点分层存下来,那么显然可以根据 $in[v],out[v]$ 在层内二分出一段属于 $v$ 的子树的节点。 那么我们进一步考虑, 阅读全文
posted @ 2019-03-24 22:04 Dilthey 阅读(216) 评论(0) 推荐(0)
摘要:题目链接:https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting game. They have a rooted tree with $n$ vertices, and 阅读全文
posted @ 2019-01-10 21:29 Dilthey 阅读(502) 评论(0) 推荐(0)
摘要:题目链接:https://codeforces.com/contest/1089/problem/E Elma is learning chess figures. She learned that a rook can move either horizontally or vertically. 阅读全文
posted @ 2018-12-03 00:10 Dilthey 阅读(615) 评论(0) 推荐(0)
摘要:题目链接: http://poj.org/problem?id=1816 http://bailian.openjudge.cn/practice/1816?lang=en_US Time Limit: 2000MS Memory Limit: 65536K Description A word i 阅读全文
posted @ 2018-11-17 11:45 Dilthey 阅读(460) 评论(0) 推荐(0)
摘要:题目链接:https://cn.vjudge.net/problem/LightOJ-1224 Given a set of $n$ DNA samples, where each sample is a string containing characters from {A, C, G, T}, 阅读全文
posted @ 2018-11-09 21:51 Dilthey 阅读(448) 评论(0) 推荐(0)
摘要:题目链接:http://poj.org/problem?id=3764 Time Limit: 2000MS Memory Limit: 65536K Description In an edge-weighted tree, the xor-length of a path p is define 阅读全文
posted @ 2018-11-08 23:40 Dilthey 阅读(325) 评论(0) 推荐(0)
摘要:题目链接:http://poj.org/problem?id=1741 Time Limit: 1000MS Memory Limit: 30000K Description Give a tree with n vertices, each edge has a length(positive i 阅读全文
posted @ 2018-10-16 13:09 Dilthey 阅读(359) 评论(0) 推荐(0)
摘要:链接:http://poj.org/problem?id=1655 Time Limit: 1000MS Memory Limit: 65536K Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N 阅读全文
posted @ 2018-10-16 12:30 Dilthey 阅读(273) 评论(0) 推荐(0)
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Problem Descrip 阅读全文
posted @ 2018-10-13 22:37 Dilthey 阅读(289) 评论(0) 推荐(0)
摘要:题目链接:http://poj.org/problem?id=1986 Description Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisur 阅读全文
posted @ 2018-07-18 12:31 Dilthey 阅读(204) 评论(0) 推荐(0)
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4514 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem Descripti 阅读全文
posted @ 2018-05-08 16:35 Dilthey 阅读(303) 评论(0) 推荐(0)
摘要:题目链接:http://codeforces.com/problemset/problem/838/B You are given a directed weighted graph with n nodes and 2n - 2 edges. The nodes are labeled from  阅读全文
posted @ 2018-05-07 21:38 Dilthey 阅读(445) 评论(0) 推荐(0)
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5692 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descript 阅读全文
posted @ 2018-05-04 10:34 Dilthey 阅读(308) 评论(0) 推荐(1)
摘要:题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1804 Bobo 有一个 n 个点,m 条边的有向无环图(即对于任意点 v,不存在从点 v 开始、点 v 结束的路径)。 为了方便,点用 1,2,…,n 编号。 设 count(x,y) 阅读全文
posted @ 2018-05-02 23:29 Dilthey 阅读(596) 评论(0) 推荐(0)
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Time Limit: 2 Seconds Memory Limit: 65536 KB Leo has a grid with N rows and M c 阅读全文
posted @ 2018-04-23 22:18 Dilthey 阅读(322) 评论(0) 推荐(0)
摘要:题目链接:http://poj.org/problem?id=2676 Time Limit: 2000MS Memory Limit: 65536K Description Sudoku is a very simple task. A square table with 9 rows and 9 阅读全文
posted @ 2018-03-27 15:41 Dilthey 阅读(458) 评论(0) 推荐(0)