上一页 1 ··· 102 103 104 105 106 107 108 109 110 ··· 182 下一页
摘要: 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)
摘要: 题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小。(先保证1号球最轻,其次2号……)分析:拓扑排序,注意根据题的要求,要先保证1号球最轻,如果我们由轻的向重的连边,然后我们依次有小到大每次把重量分给一个入度为0的点,那么在拓扑时我们面对多个入度为0的点,我们不知道该把最轻的分给谁才能以最快的速度找到1号(使1号入度为0),并把当前最轻的分给1号。所以我们要由重的向轻的连边,然后从大到小每次把一个重量分给一个入度为0的点。这样我们就不用急于探求最小号。我们只需要一直给最大号附最大值,尽量不给小号赋值,这样自然而然就会把轻的重量留给 阅读全文
posted @ 2011-07-20 20:06 undefined2024 阅读(1853) 评论(7) 推荐(0)
上一页 1 ··· 102 103 104 105 106 107 108 109 110 ··· 182 下一页