
dfs+剪枝
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
素数环(dfs&&STL做法)HDU - 1016
这题第一思路显然dfs,但是最近想了一下可以用next_permutation做,结果TLE了,究其原因,就是深搜的时候剪枝做的比较好,所以运行的时间一对比(样例是n=18),会发现dfs的解法程序在不停的输出数据,但是STL的却仅仅是在闪光标。 得结论:有的题剪枝的十分优雅(比如这题,如果1 2 判断不成立,那么第二个数放2这一大支直接剪掉了),便不能用next_permutati...原创 2018-06-07 22:22:39 · 264 阅读 · 0 评论 -
【HDU - 1518】Square (经典的dfs + 剪枝)
题干: Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square? Input The first line of input contains N, the number of test cases. Each test case begins wit...原创 2018-09-11 16:22:45 · 434 阅读 · 0 评论 -
【HDU - 1455】Sticks (dfs + 剪枝)
题干: George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had...原创 2018-09-12 09:42:31 · 247 阅读 · 0 评论 -
【PAT - 甲级 - 1018】Public Bike Management (带权最短路,多条最短路中加条件,DFS)
题干: 链接:https://www.nowcoder.com/questionTerminal/4b20ed271e864f06ab77a984e71c090f 来源:牛客网 There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over...原创 2018-10-10 16:04:19 · 465 阅读 · 0 评论 -
*【洛谷 - P1025】数的划分(dfs 或 dp 或 母函数,第二类斯特林数Stirling)
题干: 题目描述 将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序)。 例如:n=7,k=3,下面三种分法被认为是相同的。 1,1,5 1,5,1 5,1,1 问有多少种不同的分法。 输入输出格式 输入格式: n,kn,k(6<n \le 2006<n≤200,2 \le k \le 62≤k≤6) 输出格式: 11个整数,即不同...原创 2019-03-01 13:38:58 · 416 阅读 · 0 评论 -
【POJ - 1724 】ROADS (带限制的最短路 或 dfs 或 A*算法,双权值)
题干: N cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed ...原创 2019-02-14 23:51:22 · 599 阅读 · 0 评论 -
【牛客 - 373C】抓捕盗窃犯(连通图,思维,dfs 或 并查集)
题干: 链接:https://ac.nowcoder.com/acm/contest/373/C 来源:牛客网 Q市发生了一起特大盗窃案。这起盗窃案是由多名盗窃犯联合实施的,你要做的就是尽可能多的抓捕盗窃犯。 已知盗窃犯分布于NN个地点,以及第ii个地点初始有aiai名盗窃犯。 特别的是,对于每一个地点uu,都有一个固定的地点vv--当前如果某个盗窃犯位于地点uu,...原创 2019-03-02 18:24:35 · 330 阅读 · 0 评论 -
【蓝桥杯 - 真题】六角幻方(dfs+剪枝)
标题:六角幻方 把 1 2 3 ... 19 共19个整数排列成六角形状,如下: * * * * * * * * * * * * * * * * * * * 要求每个直线上的数字之和必须相等。共有15条直线哦! 再给点线索吧!我们预先填好了2个数字,第一行的头两个数字是:15 13,参见图【p1.png】,黄色一行为所求。 ...原创 2019-04-27 12:34:48 · 703 阅读 · 0 评论