HDU 5305 Friends(dfs)】的更多相关文章

Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 297    Accepted Submission(s): 127 Problem Description There are n people and m pairs of friends. For every pair of friends, they can cho…
题意:给你一个3*n的格子,中间那行表明的是周围8格(当然左右都没有)的炸弹数量,上下两行都可以放炸弹,问你有几种可能,对mod取模 思路:显然(不),当i - 1和i - 2确定时,那么i的个数一定确定,显然,只要第一列确定,后面全确定了,那么就3种可能,只要遍历到最后,最后一个符合num[n] = pre[n - 1] + pre[n]那么就说明这样排可行.复杂度O(3*n). #include<set> #include<map> #include<stack>…
Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square? Input The first line of input contains N, the number of test cases. Each test case begins with an integer 4 <= M <= 20, the number…
题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中选出5个字母,使得满足一下条件 v - w^2 + x^3 - y^4 + z^5 = n; 满足条件的可能有多组,请输出字典序最大的一组: 问题 :首先怎么找到满足条件的一组,一组字符串,对于每一个字符我们有两种选择 选||不选 ,然后在对每一个字符去进行这样的判断,然后把我们选好的5个字母在判断是否满足条…
Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175 因为题目只问能不能搜到,没问最少要几个弯才能搜到,所以我采取了DFS. 因为与Hdu 1728相比,都要考虑转弯次数,所以在判断转弯的次数上,两者可以相互借鉴. 这一点应该不难想到,在搜索前就应判断两点的值是否相等,以及两点的值中是否有0.如果不相等或其中一值为0,则可以判断是"NO". 时间虽是10000ms,但只是这样,还是超时. 后来又加了一个数组walk[][],用…
把这个写出来是不是就意味着把   http://www.hacker.org/push  这个游戏打爆了? ~啊哈哈哈 其实只要找到一个就可以退出了  所以效率也不算很低的  可以直接DFS呀呀呀呀 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> using…
Problem Description PusherBoy is an online game http://www.hacker.org/push . There is an R * C grid, and there are piles of blocks on some positions. The goal is to clear the blocks by pushing into them. You should choose an empty area as the initial…
Problem Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order. For e…
N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合法的放置方法.   Input 共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量:如果N=0,表示结束.   Output 共…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…