随笔分类 - 02.搜索 - (2)DFS
摘要:题目: 输入一个字符串,打印出该字符串中字符的所有排列。 你可以以任意顺序返回这个字符串数组,但里面不能有重复元素。 思路: 一个很直观的思路,对于任意一个字符串,例如"abcde",我首先枚举选定首字符,例如先选定了首字符是"a",那剩下部分的怎么permutation的事情就交给函数permut
阅读全文
摘要:题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 题解: 可以证明, 中最大的反质数,就是 中约数个数最多的数中,最小的那个。 证明:假设 中最大的反质数 不是
阅读全文
摘要:题目链接:http://bailian.openjudge.cn/practice/2248 题解: 迭代加深DFS。 DFS思路:从目前 中选取两个,作为一个新的值尝试放入 。 迭代加深思路:设定一个深度限制,一旦到达这个界限,即继续往下搜索;该深度限制
阅读全文
摘要:题目链接:传送门 描述 作为惩罚,GY被遣送去帮助某神牛给女生送礼物(GY:貌似是个好差事)但是在GY看到礼物之后,他就不这么认为了。某神牛有N个礼物,且异常沉重,但是GY的力气也异常的大(-_-b),他一次可以搬动重量和在w(w<=2^31-1)以下的任意多个物品。GY希望一次搬掉尽量重的一些物品
阅读全文
摘要:题目链接:https://codeforces.com/problemset/problem/570/D 题解: 这种题,基本上容易想到DFS序。 然后,我们如果再把所有节点分层存下来,那么显然可以根据 在层内二分出一段属于 的子树的节点。 那么我们进一步考虑,
阅读全文
摘要:题目链接:https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting game. They have a rooted tree with vertices, and
阅读全文
摘要:题目链接:https://codeforces.com/contest/1089/problem/E Elma is learning chess figures. She learned that a rook can move either horizontally or vertically.
阅读全文
摘要:题目链接: 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
阅读全文
摘要:题目链接:https://cn.vjudge.net/problem/LightOJ-1224 Given a set of DNA samples, where each sample is a string containing characters from {A, C, G, T},
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接: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
阅读全文
摘要:链接: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
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1804 Bobo 有一个 n 个点,m 条边的有向无环图(即对于任意点 v,不存在从点 v 开始、点 v 结束的路径)。 为了方便,点用 1,2,…,n 编号。 设 count(x,y)
阅读全文
摘要:题目链接: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
阅读全文
摘要:题目链接: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
阅读全文