摘要: View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 以前用BFS写过,这次改用DFS写发现DFS掌握的不好,挑了好久才过,今下午才AC了两道题,还要加紧练习DFS! 5 int row,col,count,vis[21][21]; 6 char map[21][21]; 7 int dx[] = {0,0,-1,1}; 8 int dy[] = {1,-1,0,0}; 9 void DFS(int x,int y)10 {11 int sx,sy,i;12 vis 阅读全文
posted @ 2012-08-03 17:48 zhongya 阅读(107) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 从第一种开始搜索,搜索完毕后回溯,搜索下一个 4 int n,m,count,sum,val[11],num[11]; 5 void DFS(int x) 6 { 7 int i; 8 if(sum == n) 9 {10 count++; 11 return ;12 }13 if(sum > n || x > m) 14 return ; 15 for(i=1; i<=num[x]... 阅读全文
posted @ 2012-08-03 16:01 zhongya 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 思路很简单,一开始没有用优先队列,WA了几次后来改了,想一想走迷宫停顿时应该用优先队列。if(u.btime==1) continue;此句不能省略当时间为1时,这一步无法出去,只有重新来过View Code 1 #include<cstdio> 2 #include<cstdlib> 3 #include<iostream> 4 #include<cstring> 5 #include<queue> 6 7 using namespace std; 8 int N,M,map[10][10]; 9 int dx[] = {0,0,- 阅读全文
posted @ 2012-08-03 15:41 zhongya 阅读(174) 评论(0) 推荐(0) 编辑