![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
BFS DFS
ERROR无限
这个作者很懒,什么都没留下…
展开
-
poj 2386 lake counting
Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water (原创 2016-04-03 16:41:27 · 243 阅读 · 1 评论 -
部分和问题
写一个简单的dfs吧///给定a1,a2...an,判断是否可以从中取出若干数,使他们的和恰为k.#includeusing namespace std;int a[10];int n, k;bool dfs(int i, int sum){ if(i == n) return sum == k; if(dfs(i+1, sum原创 2016-04-03 14:44:00 · 265 阅读 · 0 评论 -
关于 BFS 中 打印路径的问题
打印路径可以用栈的方式, 也可以用递归。下面看看用递归做的吧还是NYOJ 最少步数那道题#include #include#include#includeconst int dx[4] = {0, 0,-1, 1};const int dy[4] = {-1,1, 0, 0};struct node{ int x, y; int step;};int原创 2016-04-17 21:41:51 · 1449 阅读 · 0 评论 -
倒水问题
给定A, B两个桶。可以不停地向A, B中倒水,也可以将B中的水倒入A中,或者将A中的水倒入B中,还可以清空A,B。目标是 B桶中恰好有N加仑的水。数据是3, 5 ,4输出 倒水方式。#include#includeusing namespace std;struct condition{ int a,b;//当前两个水壶各有多少升水 int fath原创 2016-04-11 19:31:43 · 759 阅读 · 0 评论 -
部分和问题升级版
#include#include#include#include#includeusing namespace std;int a[25];int flag[25];int n,k,sum;int ok,cc,pp;void dfs(int x){ pp++;//当k为0时保证循环不会直接退出 if(ok==1)//保证只输出一组解 retur原创 2016-04-14 12:28:25 · 228 阅读 · 0 评论 -
最少步数
这有一个迷宫,有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 1,1,0,1,0,1,0,0,1 1,1,0,1,0,0,0,0,1 1,1,1,1,1,1,1,1,1原创 2016-04-14 11:23:32 · 450 阅读 · 0 评论 -
组合数
DFS真是个说不清道不明的东西#include #includeusing namespace std;int m, n;int k = 100;int a[15];bool vis[15];void dfs(int x){ if(x == n+1)///当搜到第4个的时候要退出了 { for(int j=1; j<=n; j++)///输出选好原创 2016-04-10 12:58:44 · 193 阅读 · 0 评论 -
NYOJ 三个水杯
给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个为空杯子。三个水杯之间相互倒水,并且水杯没有标识,只能根据给出的水杯体积来计算。现在要求你写出一个程序,使其输出使初始状态到达目标状态的最少次数。输入第一行一个整数N(0接下来每组测试数据有两行,第一行给出三个整数V1 V2 V3 (V1>V2>V3 V10)表示三个水杯的体积。第二行给出三个整数E1 E2原创 2016-04-13 20:24:41 · 332 阅读 · 0 评论 -
poj 3050 hopscotch
果然啊 遇到DFS就不会 要多加练习啊The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digi原创 2016-04-08 21:01:34 · 295 阅读 · 1 评论 -
poj 1979 Red and Black
Red and Blackhttp://poj.org/problem?id=1979Time Limit: 1000MSMemory Limit: 30000KDescriptionThere is a rectangular room, covered with square tiles. Each tile is col原创 2016-03-30 19:31:58 · 236 阅读 · 0 评论 -
迷宫的最短路径
简单的BFS#include #include#includeusing namespace std;const int dx[4] = {0,0,-1,1};const int dy[4] = {-1,1,0,0};struct node{ int x,y; int step;};int N,M;node now;node New;node S,T;原创 2016-04-03 21:07:31 · 359 阅读 · 0 评论 -
poj 3669 meteor shower
Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a sa原创 2016-04-07 18:07:45 · 313 阅读 · 0 评论 -
poj 3278 catch the cow
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,0原创 2016-04-05 23:25:35 · 336 阅读 · 0 评论 -
poj 2251 Dungeon Master(BFS)
Dungeon MasterTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 24330 Accepted: 9437DescriptionYou are trapped in a 3D dungeon and need to find the quic原创 2016-03-30 14:41:35 · 195 阅读 · 0 评论 -
poj 3009 curling
刚开始的时候走错了路 试图用BFS解题 浪费了不少时间///本题虽然是要找 “最短路”,但是BFS几乎不可能,因为每“走一步”,场地的状态就要///改变一次;而如果该步不满足要求,又要求把场地的状态还原到前一步,这只有DFS///能做到。///步数超过10则视为失败”的条件,这是用来剪枝的On Planet MM-21, after their Olympic game原创 2016-04-02 16:17:47 · 189 阅读 · 0 评论 -
poj 3009 新方法
///模拟所有情况#includeusing namespace std;const int inf=11;typedef class{ public: int r,c; //冰壶当前位置 bool status; //status冰壶当前状态:运动true ,静止false}SE;SE s,e; //记录冰壶起止点int w转载 2016-04-02 16:37:00 · 226 阅读 · 0 评论 -
HDU 1104 remainder
难点在于取模, km的问题,现在仍然不是很懂! 查了题解, 又发现了新的打印路径的方法。Coco is a clever boy, who is good at mathematics. However, he is puzzled by a difficult mathematics problem. The problem is: Given three integers N, K and原创 2016-04-19 16:17:34 · 382 阅读 · 0 评论