ACM_搜索
文章平均质量分 71
tagyona
独立思考。不论是做题,还是人生。
展开
-
HDU 1242 Rescue(广搜+优先队列)
第一次不看题解自己敲的广搜,纪念一下。 思路:因为要找最小的时间,所以采用优先队列来处理。由于有多个朋友,所以采用从angle搜朋友的方式来解决。 #include #include #include using namespace std; int dir[4][2]={0,1,0,-1,1,0,-1,0}; const int maxn=200+5; char s[maxn][max原创 2013-04-04 20:25:23 · 625 阅读 · 0 评论 -
POJ 1088 滑雪(DP+记忆化搜索)
直接参考了discuss后面的代码。 int DP(int i,int j) { int Max=0; if(dp[i][j]) return dp[i][j]; if(j>=1){ if(g[i][j]>g[i][j-1]){ if(Max<DP(i,j-1)) Max=DP(i,j-1);转载 2013-05-10 23:37:42 · 654 阅读 · 0 评论 -
POJ 3126 Prime Path
广搜题,自己的代码写的太长了,把yimao哥的BFS生成新数字的代码拿出来分享一下。 void divide(int x, int *b){ int t= 0; while(x) b[++t]= x%10, x/= 10; } for(int i=1; i<=4; ++i){ // 枚举数a的每一位,b[i],b[4]是最高位,b[1]是个位;原创 2013-05-08 14:13:58 · 459 阅读 · 0 评论 -
HDU 1195 Open the Lock(广搜)
很巧妙的思路,看了别人的题解才想到。 原帖链接:http://blog.sina.com.cn/s/blog_7fec19cd01010qjx.html转载 2013-04-16 01:12:25 · 620 阅读 · 0 评论 -
HDU 1175 连连看(广搜)
一开始代码判重的时候有缺陷,在调整搜索顺序的时候AC了,改别的顺序又继续WA到死.后来发现时判断当前状态是否加入时没加等号,还是太弱了~ 思路就是跑到当前点时选拐点最少的。 #include #include #include #include using namespace std; const int maxn=1000+5; int n,m; int a[maxn][maxn],原创 2013-04-15 21:35:20 · 582 阅读 · 0 评论 -
HDU 1072 Nightmare(广搜)
由于可以回到原地,所以多种状态可以叠加,不处理容易超时。增加一个二维数组判断到该点时剩余时间的最大值,如果当前状态的剩余时间大于该值,则加入队列,否则舍弃。 #include #include #include #include using namespace std; const int maxn =10+5; int a[maxn][maxn]; int n,m,si,sj; boo原创 2013-04-15 19:01:37 · 539 阅读 · 0 评论 -
HDU 1495 非常可乐(广搜)
原帖链接:http://blog.csdn.net/ilovexiaohao/article/details/8564830 可乐体积为S,互相之间来回倾倒饮料,判断是否可以将S平分。广搜所有的状态即可。 这份代码的优越在于二层for循环的使用,有效避免的冗长重复的代码。 #include #include #include #include using namespace std;转载 2013-04-14 16:37:23 · 789 阅读 · 0 评论 -
HDU 1026 Ignatius and the Princess I(记忆化搜索)
广搜习惯了用队列,遇到一道输出路径的题就卡了。其实可以用数组来模拟队列,用DP的方法来求从终点到起点的最小值,这就是所谓的记忆化搜索:算法上依然是搜索的流程,但是搜索到的一些解用动态规划的那种思想和模式作一些保存。 别人的代码我就不贴原创了,支持正版。 #include #include #include using namespace std; const int inf=100000转载 2013-04-14 19:30:25 · 898 阅读 · 0 评论 -
HDU 2553 N皇后问题(深搜)
#include #include #include #include using namespace std; const int maxn=10+5; int m[maxn],res[maxn]; bool hash[maxn]; int ans,n; void DFS(int k) { if(k==n+1) { ans++; retur原创 2013-04-14 17:19:22 · 563 阅读 · 0 评论 -
HDU 1015 Safecracker(深搜)
#include #include using namespace std; const int maxn=30+5; char s[maxn],l[maxn],r[maxn]; int len,tar,sum,st; bool flag,vis[maxn]; void dfs() { if(st<5) { for(int i=0; i<len; i++)原创 2013-04-09 22:18:16 · 731 阅读 · 0 评论 -
HDU 1429 胜利大逃亡(续)(广搜+状态压缩)
用某二进制位代表该钥匙是否存在。如10010表示有第1把和第5把钥匙(下标从0开始)。 当遇到小写字母时,将key的值改变,方法是key=key|(1 当遇到大写字母时,判断该钥匙是否存在的方法是key&(1 #include #include #include using namespace std; const int maxn=25; bool hash[maxn][maxn原创 2013-04-13 14:07:11 · 563 阅读 · 1 评论