Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m square blocks of size 1×1. Due to the friction with the frame and each other, the blocks are stable and will not drop. However, the blocks can be knocked…
DES:从23个队员中选出4—4—2—1共4种11人来组成比赛队伍.给出每个人对每个职位的能力值.给出m组人在一起时会产生的附加效果.问你整场比赛人员的能力和最高是多少. 用深搜暴力枚举每种类型的人选择情况.感觉是这个深搜写的很机智. 在vector中存结构体就会很慢.TLE.直接存序号就AC了.以后还是尽量少用结构体吧. #include<stdio.h> #include<string.h> #include<map> #include<vector>…
中文题 深搜 许久没写鸟,卡在输入问题上... #include <iostream> #include <string> using namespace std; bool flg; int n; ][]; ]; void dfs(int p) { int i; if (p >=n || flg) return; ] == 'm') { flg = true; return; } ; i<n; i++) ] == str[p][]) { used[i] = true;…
深度搜索 剪枝 还不是很理解 贴上众神代码 //http://blog.csdn.net/vsooda/article/details/7884772#include<iostream> #include<math.h> using namespace std; char map[10][10]; int N,M,T; int di,dj,escape; int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; void dfs(int x,int y,…
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 5 int f[N]; int visit[N]; int vis[10000]; void dfs(int sum,int k) { int i; if(k==4) { if(vis[sum]==0) vis[sum]=1; return ; } for(i=0;i<4;i++) { if(visit[i]==0) { visit[…
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; ],n,El; ]; int dfs(int k,int pos,int nowlen) { int i,j; if(nowlen==El) { if(k==n) ; else nowlen=,pos=; } for(i=pos…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5648 题意:给定n,m(1<= n,m <= 15,000),求Σgcd(i|j,i&j);(1 <= i <= n,1<=j<=m); 至多三组数据,至多两组数据max(n,m) > 2000.至多一组数据max(n,m) > 8000; 很多题解是用递推打表,将数据压缩250倍,即[i][j]:代表[1...250*i][1...250*j],之后零…
题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的分值.//解题思路:记忆化搜索,状态出来就非常水,dp[fl][fr][sl][sr][flag],//表示第一堆牌上边取到fl,下面取到fr,同样sl,sr为第二堆牌,flag为第几个人在取.//如果是第一个人,dp既要尽量大,如果是第二个人,那么肯定尽量小. http://www.2cto.co…
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #include <iostream> using namespace std; ][]; int p,q; void dfs(int x,int y){ land[x][y] = '*'; ][y]!= ][y] != ] != ] != ][y+]!= ][y-] != ][y-] != ][y+] !…
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇.. 思路: 模拟,深搜.. 用类似时间戳的东西给方格标记上,表示某一秒正好走到该方格.. 最后遍历一下驴在某一格方格标记时间是否和老虎在该格标记的时间一样,一样代表正好做过这里了.. 还有一种情况就是老虎或驴一直停在那里,那就算不相等,也是可以的.. Tips: 我一直忘了老虎或驴停下来的情况,这样…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18758    Accepted Submission(s): 10806 Problem Description The GeoSurvComp geologic survey comp…
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10541    Accepted Submission(s): 3205Special Judge Problem Description The Princess has been abducted by the BEelzebub…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! #include <iostream> #include <cstdio> #include<algorithm> #include <cstring> using namespace std; ],visit[]; int l,n; int dfs(int…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 149833    Accepted Submission(s): 39945 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Block Breaker Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m sq…
题目链接:https://vijos.org/p/1159 https://www.luogu.org/problem/show?pid=1494 这是今天的第三道迭代深搜的题,虽然都是迭代深搜的模板,都是一些基础题,但是还是觉得自己不行啊... 拿到题目后我就有了一个大胆的想法 然后自己仔细斟酌之后我就pass了他...我原本想在dfs中来记录下有几种水桶,现在询问的是哪一个水桶,当前这个水桶选了几个... 然而,这个想法实在是太大胆了.......在一番斟酌之后,我想到了一个神奇的东西叫记忆…
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to save Angel. Their task is: approa…
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and his factory, were destroyed in Wo…
N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1757    Accepted Submission(s): 772   Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上.你的任务是,对于给定的N,求出…
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5437    Accepted Submission(s): 1372 Problem Description You have been given a matrix CN*M, each element E of CN*M is positive…
题目链接 Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合法的放置方法. Input 共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量:如果N=0,表示结束.   Output 共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量.   Sample Input 1 8 5 0   Sample Output 1…
题目 这是传说中的深搜吗....不确定,,,,貌似更加像是模拟,,,, //我要做深搜题目拉 //实际上还是模拟 #include<iostream> #include<string> #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int ans; ]; __int64 n; ]; int l…
Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9588    Accepted Submission(s): 3127 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end…
#include<stdio.h>#include<string.h>char mapp[220][220];int m,n,mmin;void dfs(int x,int y,int time){  if(mapp[x][y]=='#'){   return ;  }  if(x<0||x>=m||y<0||y>=n){   return ;  }  if(mapp[x][y]=='a'){         dfs(x,y+1,0);         df…
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m square blocks of size 1×1. Due to the friction with the frame and each other, the blocks are stable and will not drop. However, the blocks can be knocked…
果然集训就是学长学姐天天传授水铜的动态规划和搜索,今天讲DP由于困意加上面瘫学长"听不懂就是你不行"的呵呵传授,全程梦游.最后面对连入门都算不上的几道动态规划,我的内心一片宁静,甚至有一丝的想笑. 弱鸡第一次写博客,来分享一些对汉诺塔问题的理解吧: http://www.cnblogs.com/fanzhidongyzby/archive/2012/07/28/2613173.html 遵从tls"遇到不懂问题就xjb乱搜"原则,搜到了这篇文章.看完之后基本有了点眉…
因为前两天某网站的比赛一个深搜错了,我只得了3等奖,我找不到错误,给别的大佬看他们又嫌恶心.emm……,比赛结束后我自己反思了一下,深搜写错了该怎么办,或者说怎样避免写错. 首先,变量名不要太ex,比如比赛时那道深搜,我用了x,xx,xxx,y,yy,yyy等变量.当时觉得没什么,时候看看恶心死人了.如果你不小心记错了,找的时候面对一群x,那最好的方法就是重写了. 其次,我推荐大家深搜写错就重写一遍,尤其是长的.写起来恶心的.真的不好找,万一你走了一下神,然后让你在近百行代码里找bug,真的很让…
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3014    Accepted Submission(s): 1323 Problem Description Now an emergent task for you…
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m soda and today is their birthday. The 1-st soda has prepared n cakes with size 1,2,…,n. Now 1-st soda wants to divide the cakes into m parts so that th…
POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the…