![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dfs
文章平均质量分 89
pmt123456
这个作者很懒,什么都没留下…
展开
-
hdu1142(dijastra+记忆化搜索)
题目链接A Walk Through the Forest 记忆化搜索介绍 hdu1078 如果从B到home的路比任何从home到A的路要短,那么久有一条A从到B的路,计算一个可以由几条路 如图 dfs(1) ⑴ A->2,return 1, p[A]+=1 p[1]+=1 ===>p[A]=1 p原创 2016-12-05 19:49:27 · 347 阅读 · 0 评论 -
hdu1078(记忆化搜索)
题目链接FatMouse and Cheese 一个网格上有很多cheese,老师偷cheese吃,每次四邻域最多走k步,下一步的cheese数必须必当前位置多,求能吃到的最多cheese 记忆化搜索原创 2016-11-26 14:10:50 · 379 阅读 · 0 评论 -
hdu1181(DFS)
题目连接:变形课 以a开头b结尾的一个单词,可以使A物体变成B物体,问是否能把Ball变成Mouse DFS:建图,以a开头b结尾的单词就在ab之间连一条边 代码 #include #include #include #include using namespace std; const int maxl=1005; char str[maxl]; bool g[26原创 2016-12-09 17:06:24 · 245 阅读 · 0 评论 -
hdu1198(DFS/并查集)
题目链接:Farm Irrigation 如左图所示,有11种管道,问给定一个图,最少要挖几个井才能灌溉到所有的管道 如右图,至少需要三个井口 两种做法DFS和并查集 难点在管道接口的判断:将一个块变成四个点,有管道伸出就是1,否则就为0 判断两个块是否在该方向管道是想通的 用&就可以了 int pipe[][4]={ {1,0,1,0}, {1原创 2016-12-09 18:37:49 · 338 阅读 · 0 评论 -
hdu1258(dfs)
题目链接:Sum It Up 题目大意:给出一组数a[n]={x1,x2,x3...xn}和t,求出a[n]的子集使得子集中的元素之和=t 每个数只能使用一次,不能输出重复的子集 分析:简单dfs,vis判断某个数是否使用过 !!!注意不能输出两个相同的子集,即某个数不能再相同的位置使用两次 用last记录上次此位置使用的数,若相同则跳过 #include #include co原创 2017-01-04 20:59:33 · 286 阅读 · 0 评论 -
hdu 1045(dfs暴搜/缩点+二分图最大匹配(典型行列匹配题))
一、dfs暴搜 参见八皇后问题,(搜索其四个方向)判断每一个格子能不能放,能放,就标记为'@' 因为棋盘大小最多为4,所以不会TLE #include #include using namespace std; char g[5][5]; int tot, sz, ans; int dx[] = { -1, 1, 0, 0 }; int dy[] = { 0, 0, -1, 1 };原创 2016-11-03 23:34:07 · 382 阅读 · 0 评论 -
hdu1016 (素数表+回溯)
白书上的原题吧。 #include #include #include #include using namespace std; const int maxn=45; int prime[maxn]; int vis[21]; int path[21]; int n; void init() { memset(prime,-1,sizeof(prime)); memset(原创 2016-09-24 23:21:21 · 328 阅读 · 0 评论 -
hdu 1027(全排列)
1、暴力dfs,没有技巧 #include #include #include using namespace std; const int maxn=1005; int a[maxn]; int vis[maxn]; int n,m; int c; bool flag; void init() { flag=false; c=0; memset(vis原创 2016-10-09 10:48:47 · 480 阅读 · 0 评论