摘要:
dfs题意:给定一个大正方形的边长,和若干个小正方形的边长,问大的能否由小的拼成。分析:我们从上到下,从左到右地拼,也就是没列在任意时刻都是上面一段连续的空间被占用,用len[i]记录第i列被占用了几格。用cnt[i]记录边长为i的正方形有几个,枚举要拼的正方形的时候枚举i,这样可以保证当一个正方形匹配失败时,相同的正方形不会被反复尝试。每次选择一个正方形拼到最靠上端的空间中,如果任何正方形都没法拼,则说明那块空间永远无法被占用,所以应该回溯。View Code #include <iostream>#include <cstdio>#include <cstdl 阅读全文
posted @ 2011-07-21 15:46
undefined2024
阅读(926)
评论(2)
推荐(1)
摘要:
dfs没剪枝就过了……View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxm 23#define maxn 8struct Order{ int s, e, p;}order[maxm];int cap, n, m;int ans;int ocount;int down[maxn];bool operator < (c 阅读全文
posted @ 2011-07-21 11:43
undefined2024
阅读(471)
评论(0)
推荐(0)
摘要:
dfsView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 65bool g[maxn][maxn];int ans;int n;int c[maxn];bool vis[maxn];int lonely[maxn];void check(int t){ memset(vis, 0, sizeof(vis)); memset(lonely, 0, sizeof(lonely 阅读全文
posted @ 2011-07-21 10:44
undefined2024
阅读(363)
评论(0)
推荐(0)
摘要:
bfs细节处理比较麻烦View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>using namespace std;#define maxn 80struct Node{ int x, y, turn, d;};bool map[maxn][maxn];int vis[maxn][maxn];int m, n;int x1, y1, x2, y2;int dir[4][2] ={{ 1, 0 } 阅读全文
posted @ 2011-07-21 09:59
undefined2024
阅读(463)
评论(0)
推荐(0)