码迷,mamicode.com
首页 >  
搜索关键字:dfs    ( 10564个结果
皇后问题
递归回溯代码#include using namespace std;int n,m, a[10];bool bz[3][10];void DFS(int k){ int i;if (k==n) { for ( i=0; i>n; DFS(0);return 0;}V...
分类:其他好文   时间:2014-08-03 17:52:45    阅读次数:299
深度优先DFS
深度优先(DFS)模板1:void DFS(int k) //处理第k步{ if (k==n) //已经处理到第n步,到达目的状态 输出结果 else//处理第k步 for (int i=1; iusing namespace std;int n,m, a[10];void DFS(int k).....
分类:其他好文   时间:2014-08-03 15:10:35    阅读次数:194
重连通量的邻接矩阵和邻接表两种形式的求法
邻接矩阵:#include #include #include using namespace std;#define min(a,b) a s;void dfs(int u){ Edge t,tt; dfn[u]=low[u]=++tmpdfn,visit[u]=1; for(i...
分类:其他好文   时间:2014-08-03 15:07:56    阅读次数:256
HDU 2196Computer(树形DP)
给你一颗边带权值的树,求树上的每一点距离其最远的一个点的距离比较典型的题了,主要方法是进行两次DFS,第一次DFS求出每一个点距离它的子树的最远距离和次远距离,然后第二次DFS从父节点传过来另一侧的树上的距离它的最远距离进行一次比较便可得出任意点的最远距离了之所以需要记录最远和次远是为了辨别父节点的...
分类:其他好文   时间:2014-08-03 15:04:35    阅读次数:215
nyist oj 58 最少步数(dfs搜索)
最少步数 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 这有一个迷宫,有0~8行和0~8列:  1,1,1,1,1,1,1,1,1  1,0,0,1,0,0,1,0,1  1,0,0,1,1,0,0,0,1  1,0,1,0,1,1,0,1,1  1,0,0,0,0,1,0,0,1  1,1,0,1,0,1,0,0,1...
分类:其他好文   时间:2014-08-03 12:52:45    阅读次数:246
poj 1088 滑雪 【记忆化搜索】+【DFS】
策略:如题 题目链接:http://poj.org/problem?id=1088 代码: #include #include int map[105][105], dp[105][105], n, m; const int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; //四个方向 int limit(int x, int y) //判断是不是越界了 {...
分类:其他好文   时间:2014-08-03 12:50:25    阅读次数:224
HDU-2821-Pusher(DFS)
Problem Description PusherBoy is an online game http://www.hacker.org/push . There is an R * C grid, and there are piles of blocks on some positions. The goal is to clear the blocks by pushing into t...
分类:其他好文   时间:2014-08-02 23:27:34    阅读次数:342
Codeforces 453C Little Pony and Summer Sun Celebration dfs树上构造
题目链接:点击打开链接 题意: 给定一个无向图 任选一个起点,使得访问每个点的次数奇偶与最后一行的输入一致 思路: 选一个奇数点作为起点 dfs树一下,若子节点不满足则先走到子节点再回来 如此就能保证所有子节点合法 这样dfs结束后最多只有根节点不满足,随便找一个与根相连的点调整一下。 #include #include #include #include #includ...
分类:其他好文   时间:2014-08-02 21:02:49    阅读次数:433
hdu 1501 Zipper (dfs+记忆化搜索)
Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6491    Accepted Submission(s): 2341 Problem Description Given three strings...
分类:其他好文   时间:2014-08-02 21:01:44    阅读次数:297
Unique Paths
问题:从起点到终点总共有多少条路径分析:f[x,y]=f[x+1,y]+f[x,y+1],用记忆化搜索就可以解决了class Solution {public: int num[110][110]; int dfs(int m,int n,int x,int y) { ...
分类:其他好文   时间:2014-08-02 20:39:33    阅读次数:165
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!