DFS POJ 2362 Square】的更多相关文章

题目传送门 /* DFS:问能否用小棍子组成一个正方形 剪枝有3:长的不灵活,先考虑:若根本构不成正方形,直接no:若第一根比边长长,no 这题是POJ_1011的精简版:) */ #include <cstdio> #include <iostream> #include <cstring> #include <map> #include <set> #include <cmath> #include <algorithm&g…
传送门:http://poj.org/problem?id=2362 题目大意: 给一些不同长度的棍棒,问是否可能组成正方形. 学习了写得很好的dfs 赶紧去玩博饼了.....晚上三个地方有约.....T T分身乏术啊.... #include<cstdio> #include<algorithm> using namespace std; const int MAXN=22; int side[MAXN],target,n; bool vis[MAXN]; bool dfs(in…
题意:给n个木棍,问能不能正好拼成一个正方形. 解法:POJ1011的简单版……不需要太多剪枝……随便剪一剪就好了……但是各种写屎来着QAQ 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<limits.h> #include&…
Square Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 21821   Accepted: 7624 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 nu…
题目大意:给你T组数据,每组数据有n个棍子,问你能不能用这些棍子拼成一个正方形(所有都要用上,而且不能截断棍子). Sample Input 34 1 1 1 15 10 20 30 40 508 1 7 2 6 4 4 3 5Sample Output yesnoyes 芒果君:我以为这只是一道简单的dfs,没想到它虽然是简单的dfs,结果为了剪枝到不tle,耗了我整整两节自习课,人家明明和题解写的差不多来着,嘤嘤嘤,人家超想哭的>_< 至于怎么剪枝代码里已经很明显了,不容易想到的是,如果已…
POJ 3411 Paid Roads Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2430 Description A network of m roads connects N cities (numbered from 1 to N). There may be more than one road connecting one city with another. Some o…
题目链接: http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14546   Accepted: 3837 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cav…
题目传送门 /* 题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子 DFS:直接模拟搜索,用map记录该字符串是否被搜过.读懂题目是关键. */ /************************************************ Author :Running_Time Created Time :2015-8-3 13:57:55 File Name :POJ_3087.cpp ***********************…
题目传送门 /* DFS:因为一行或一列都只放一个,可以枚举从哪一行开始放,DFS放棋子,同一列只能有一个 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ][]; ]; int n, k, ans; void DFS(int x, int num) { ; i<=n; ++i) { if (maze[x][i] == '#' &&…
对于深度优先算法,第一个直观的想法是只要是要求输出最短情况的详细步骤的题目基本上都要使用深度优先来解决.比较常见的题目类型比如寻路等,可以结合相关的经典算法进行分析. 常用步骤: 第一道题目:Dungeon Master  http://poj.org/problem?id=2251 Input The input consists of a number of dungeons. Each dungeon description starts with a line containing th…