
NOIP 搜索
_Tham
If you sleep now , you will hava a dream. But if you study now , you will achieve your dream.
展开
-
搜索+剪枝——POJ 1011 Sticks
搜索+剪枝——POJ 1011 Sticks 博客分类: 算法 非常经典的搜索题目,第一次做还是暑假集训的时候,前天又把它翻了出来,本来是想找点手感的,不想在原先思路的基础上,竟把它做出来了而且还是0ms过得。仔细想想,对搜索又有了一点点认识。 题目要求将一系列的sticks重新组合,形成若干相等相等长度的木棒,且尽量使木棒长度最小,如果数据量比较小的转载 2014-08-05 09:51:34 · 907 阅读 · 0 评论 -
图的基本操作(基于邻接表):图的构造,深搜(DFS),广搜(BFS)
#include #include #include using namespace std; #define MAXN 100 struct ArcNode { int adjVertex; //边到的顶点 ArcNode *next; }; struct VNode { string d原创 2014-12-02 16:04:05 · 1165 阅读 · 0 评论 -
全排列(递归方法,模板实现)
#include using namespace std; template void Perm(T a[], int k, int m) { if(k==m) { for(int i=0; i<=m; i++) cout<<a[i]; cout<<endl; }原创 2015-04-10 15:44:39 · 875 阅读 · 0 评论 -
邻接矩阵实现图的存储,DFS,BFS遍历
#include #define GRAPHMAX 10 #define FALSE 0 #define TRUE 1 #define Error printf #define QueueSize 30 typedef struct { char vexs[GRAPHMAX]; int edges[GRAPHMAX][GRAPHMAX]; int n,e; }Mgrap原创 2014-09-02 17:14:45 · 6585 阅读 · 0 评论 -
双向BFS—>NOIP2002 字串变换
如果目标也已知的话,用双向BFS能很大提高速度 单向时,是 b^len的扩展。 双向的话,2*b^(len/2) 快了很多,特别是分支因子b较大时 至于实现上,网上有些做法是用两个队列,交替节点搜索 ×,如下面的伪代码: while(!empty()) { 扩展正向一个节点 遇到反向已经扩展的return原创 2015-09-17 21:01:20 · 1191 阅读 · 0 评论 -
(皇后移动类)八数码难题引发的搜索思考及总结
POJ 1077 Eight The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 o原创 2016-07-19 14:43:04 · 4237 阅读 · 0 评论 -
N皇后问题(状态压缩实现)
题目链接~~> 这题用 dfs()N范围一大了过不了,需要打表,用状态压缩可以状态压缩真是太强大了。 状态压缩 1: 在状态压缩中,通常用 ( 1 一、DFS函数参数Col,MainDiag,ContDiag的表示意义: 当整形数Col,MainDiag,ContDiag的第X位为1时,表示因为之前摆放的皇后的纵向攻击,主对角线斜向攻原创 2017-02-17 11:10:24 · 2319 阅读 · 2 评论