hdu 4090--GemAnd Prince(搜索)】的更多相关文章

题目大意: 别人说是消消看,至于你玩没玩过.反正我是没玩过的. 就是选择一个钻石,可以消除与它相连的所有钻石.并获得 消除数量*消除数量  的分 思路: 直接暴搜,然后用一个cnt数组表示每一种钻石剩余的数量,进行剪枝. 被坑了两天. 开始用BFS 搜,用DFS进行标记.超内存. 后来改成了  DFS + DFS 发现有些细节不好处理. 最后换成了DFS搜  BFS标记消除. #include <iostream> #include <cstdio> #include <al…
GemAnd Prince Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 872    Accepted Submission(s): 299 Problem Description Nowadays princess Claire wants one more guard and posts the ads throughout t…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4616 这道题目数据可能比较弱,搜索都可以AC,但是不敢写,哎…… 搜索AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <vecto…
A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15567    Accepted Submission(s): 3886 Problem Description 可 怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃 公主的肉也能长生不…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 思路:简单的记忆化搜索,留意一下A==0时的情况就可以了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; ]; ll dp[][]; ll dfs(int pos,int…
题目链接: hdu 5335 Walk Out 题目描述: 有一个n*m由0 or 1组成的矩形,探险家要从(1,1)走到(n, m),可以向上下左右四个方向走,但是探险家就是不走寻常路,他想让他所走的路线上的0/1组成的二进数最小,现在要为矫情无比的探险家找最优路径咯. 解题思路: 对于二进制数,前导零是对数字大小没有任何影响的.当到不得不走1的时候就只能向下,或者向右走了.所以先搜索出来一直走零,能走到的最靠近终点的位置,然后在类似搜索,找出最优路径. #include <queue> #…
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <queue> using namespace std; #define N 100003 struct node { int p,d; bool opera…
Y - How many ways Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1978 Appoint description: Description 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m).游戏的规则描述如下: 1.机器人一开始在棋盘的起始点并有起始点所标有的能量. 2.机器…
² 博弈取牌—记忆化搜索 题目描述: 有两副带有数字的牌,(数字>0)两人轮流取,取中了某张牌,自己的分数就加上牌上的数字,但只能从两端取,每人都会用最优的策略使得自己的分数最高.问A先取,他能得到的最高的分数. 解法: 记忆化搜索,对于第一.二副牌的左右端点分别为fr1,ta1, fr2,的情形,某个人能拿到的分数的最大值这次取走牌fr1,ta1,fr2,ta2中的最大值,牌的数目减1,问题规模被缩小.边界条件为当没有牌时为0.因为两个人都是这么思考,可抽象成一个人.当总分数为sum时,我能得…
http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 732    Accepted Submission(s): 356 Problem Description The twenty-first century is a…
典型的bfs模拟 (广度优先搜索) ,不过有好多细节要注意,比如图中如果是  R#  走到这个R的话就无限往右走了,这样就挂了~肯定到不了出口.还有一种容易造成死循环的,比如 #E## DLLL D. .U D.SU RRRU 这样的话就必须要标记下当前位置某个方向获得钥匙的状态是否被访问过了,获得钥匙的状态可以状态压缩来表示. 墙角如果遇到转弯了是不会加step的! #include <stdio.h> #include <string.h> #include <queue…
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N 向 M 倒 4. N 向 S 倒 5. M 向 S 倒 6. M 向 N 倒 根据上述的六种情况来进行模拟, 每次模拟的结果都放进队列里面. 注意: 还要用到标记数组,防止数据重复进入队列导致爆栈. #include<stdio.h> #include<stdlib.h> #incl…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 //dp[i][j]表示从点i,j处开始能获得的最多cheese #include <iostream> #include <string.h> #include <stdio.h> using namespace std; int n,k,dp[101][101],map[101][101]; int dfs(int a,int b){ if(dp[a][b]) r…
给出五子棋残局,推断三步内能否分出胜负,玩家为当前该走旗子的颜色,下一步为白棋或黑棋不定. 依照顺序推断就可以: 1:推断棋盘是否合法,并确定玩家颜色 2:推断当前玩家颜色是否有一个必胜点,有玩家则在第一步胜 3:推断还有一方在当前是否有两个必胜点,若有,则玩家在第二步失败 4:BFS出玩家是否存在此方案:随意放置一个位置的前提下,还有一方没有必胜点,且玩家有两个必胜点,则玩家在第三步胜 5:否则3步内无法分出胜负 #include "stdio.h" #include "s…
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two differen…
题意: 给你一个初始的图,然后每次输入一个图,要求移动x最小的步数达到和初始图一样,输出路径 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 5 6 7 8 5 6 7 8 5 6 7 8 5 6 7 8 9 x 10 12 9 10 x 12 9 10 11 12 9 10 11 12 13 14 11 15 13 14 11 15 13 14 x 15 13 14 15 x r-> d-> r-> 好像有很多中方法解决这个问题:八数码的八个境界 ①bfs + 康托展开…
题目链接 Problem Description In mathematics, the four color theorem, or the four color map theorem, states that, given any separation of a plane into contiguous regions, producing a figure called a map, no more than four colors are required to color the…
题意是给4堆(堆的高度小于等于40)有颜色(颜色的种类小于等于20)的物品,你有一个篮子最多能装5件物品,每次从这4堆物品里面任取一件物品放进篮子里,但是取每堆物品时,必须先取上面的物品,才能取下面的物品,如果发现篮子里的两种物品的颜色一样,那么把这两种物品拿出来,问最后最多能拿出多少对物品?:解题思路:记忆化搜索+dp+状态压缩:因为40×40×40×40不会太大,所以可以用dp[x[1]][x[2]][x[3]][x[4]]记录搜索的状态:dp[x[1]][x[2]][x[3]][x[4]]…
题目大意:只能按照格子上的数字*方向走,从左上走到右下Sample Input42331121312313110Sample Output3 直接记忆化搜索,注意是0的情况 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using…
Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 21    Accepted Submission(s): 14 Problem Description In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move ho…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 144191    Accepted Submission(s): 38474 Problem Description The doggie fou…
超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3866    Accepted Submission(s): 1241 Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密 码是一个C进制的…
The K-th Distance Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 752    Accepted Submission(s): 216 Problem Description Given a tree, which has n node in total. Define the distance between two…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1426 题意很明确,让你解一个9*9的数独. DFS即可. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define REP(i,n) for(int i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5339 题意:一个整数a 和一个数组b.问你能否在b中取出r个元素排列组成c数组满足a%c1%c1%-..%cr == 0.输出最小的r,不能满足条件输出-1. 思路:b按从大到小排序,暴搜. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include…
Another OCD Patient Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 490    Accepted Submission(s): 180 Problem Description    Xiaoji is an OCD (obsessive-compulsive disorder) patient. This mo…
/* 记忆化搜索,第二维判断是否是6 */ #include<stdio.h> #include<string.h> #define N 9 int dp[N][2],digit[N]; int dfs(int len,int cnt,int ok) {//cnt代表是否是6,ok代表前一个是当前为最大值,并且当前也是最大值 if(!len)return 1; if(!ok&&dp[len][cnt]!=-1)return dp[len][cnt]; int i,a…
Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 141    Accepted Submission(s): 17 Problem Description In an n∗m maze, the right-bottom corner is the exit (position (n,m) is the exit).…
题意: 给你一个数,求在多少种不同的进制下这个数每一位都是3.4.5.6中的一个. 思路: 搜索.枚举这个数在任意进制下的表示,判断是否合法.当数字只有3.4.5.6时,必定有无穷种. 因为数字太大,所以直接枚举必定会超时. 下面有两种剪枝的方法: 1. 先枚举最后一位的情况. 假设数字n在base进制下表示为 a[n]...a[0],即 n = a[0] + a[1]*base^1 + ... + a[n]*base^n. 则 n - a[0] = a[1]*base^1 + ... + a[…
原题链接: 大致题意:给你一个二维字符串,可以看成图:再给两个子串“girl”和“cat”,求图中任意起点开始的不间断连接起来的字母构成的两个子串的分别的个数:连接的方向只有不间断的上下左右. 搜索函数: void dfsgirl(int i, int j,int k); //第一层(i1,j1,  k=0)时,k=0表示(i1,j1)上是g,然后枚举四个方位找到i——进入第二层//第二层(i2,j2,   k=1)时,k=1表示(i2,j2)位置上是字母i(并且该位置与i1,j1相邻,这是为什…