深度优先搜索(DFS)是搜索算法的一种。最早接触DFS应该是在二叉树的遍历里面,二叉树的先序、中序和后序遍历实际上都属于深度优先遍历,实质就是深度优先搜索,后来在图的深度优先遍历中则看到了更纯正的深度优先搜索算法。
通常,我们将回溯法和DFS等同看待,可以用一个等式表示它们的关系:回溯法=DFS+剪枝。所以回溯法是DFS的延伸,其目的在于通过剪枝使得在深度优先搜索过程中如果满足了回...
分类:
其他好文 时间:
2014-07-08 20:34:20
阅读次数:
271
题意:给你一个数字字符串,问在字符串中间加‘=’、‘+’使得‘=’左右两边相等。
1212 : 1+2=1+2, 12=12;
12345666 : 12+3+45+6=66, 1+2+3+4+56=66;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#inc...
分类:
其他好文 时间:
2014-07-08 14:41:26
阅读次数:
243
原题: ZOJ 3686http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3686这题本来是一个比较水的线段树,结果一个mark坑了我好几个小时。。哎。太弱。先DFS这棵树,树形结构转换为线性结构,每个节点有一个第一次遍历的时间...
分类:
其他好文 时间:
2014-07-08 00:46:56
阅读次数:
295
原题: ZOJ 3675http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3675由m#include #include #include #include #include using namespace std;#defin...
分类:
其他好文 时间:
2014-07-08 00:31:26
阅读次数:
272
题目如下:
Bicoloring
In 1976 the ``Four Color Map Theorem" was proven with the assistance of acomputer. This theorem states that every map can be colored using only fourcolors, in...
分类:
其他好文 时间:
2014-07-06 12:28:07
阅读次数:
241
题目如下:
Problem A: The Monocycle
A monocycle is a cycle that runs on one wheel and the one we will be considering is a bit more special. It has a solid wheel colored with fiv...
分类:
其他好文 时间:
2014-07-06 11:49:47
阅读次数:
233
题目链接:点击打开链接
题意:
给定n个节点的树
1为根
则此时叶子节点已经确定
最后一行给出叶子节点的顺序
目标:
遍历树并输出路径,要求遍历叶子节点时按照给定叶子节点的先后顺序访问。
思路:
给每个节点加一个优先级。
把最后一个叶子节点到父节点的路径上的点优先级改为1
把倒数第二个叶子节点到父节点的路径上的点优先级改为2
如此每个点就有一个优先级,每个访问儿子节...
分类:
其他好文 时间:
2014-07-06 10:11:10
阅读次数:
193
写哭了,本来感觉是floyd,但是发现floyd根本不能连续地传递,然后看了题解写了个搜索,这个搜索我都没有想到= =
先贴个floyd的代码,先试图用DFS处理连续控股的情况,再用几个循环处理k1+k2+k3+...Kn
在第八组数据跪了
/*
ID:kevin_s1
PROG:concom
LANG:C++
*/
#include
#include
#include
#inclu...
分类:
其他好文 时间:
2014-07-06 09:52:55
阅读次数:
189
The Game
Description
One morning, you wake up and think: "I am such a good programmer. Why not make some money?'' So you decide to write a computer game.
The game takes place on a rectangular...
分类:
其他好文 时间:
2014-07-06 09:02:34
阅读次数:
287
题目来源:Light OJ 1429 Assassin`s Creed (II)
题意:最少几个人走完全图 可以重复走 有向图
思路:如果是DAG图并且每个点不能重复走 那么就是裸的最小路径覆盖 现在不是DAG 可能有环 并且每个点可能重复走 对于有环 可以缩点 缩点之后的图是DAG图 另外点可以重复走和POJ 2594一样 先预处理连通性
#include
#include
#incl...
分类:
其他好文 时间:
2014-07-06 00:15:53
阅读次数:
270