上一页 1 ··· 150 151 152 153 154 155 156 157 158 ··· 182 下一页
摘要: 暴力搜索dfs,注意要利用递归来减少计算总通信量的次数。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 21int map[maxn][maxn], ans = 0;bool in[maxn];int n;void dfs(int now, int sum){ if (now > n) { if (sum > ans) ans = sum; return; 阅读全文
posted @ 2011-05-17 21:19 undefined2024 阅读(570) 评论(0) 推荐(0)
摘要: 线段树,线段树一般是对连续的区块进行操作,每次给出相应的区块,但是本题给出海报覆盖的是区间,要把区间对应到区块上。虽然有些情况还不能处理,但是过了。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 20005struct Interval{ int s, e;}interval[maxn];struct Node{ N 阅读全文
posted @ 2011-05-17 20:51 undefined2024 阅读(880) 评论(1) 推荐(0)
摘要: 简单并查集View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 50004int father[maxn];int getanc(int a){ if (father[a] == a) return a; return father[a] = getanc(father[a]);}void merge(int a, int b){ if (father[a] == -1) 阅读全文
posted @ 2011-05-17 19:23 undefined2024 阅读(212) 评论(0) 推荐(0)
摘要: 题意:有k种物品,m个供应商,n个收购商。每个供应商和收购商都需要一些种类的物品若干。每个供应商与每个收购商之间的对于不同物品的运费是不同的。求满足收购商要求的情况下,最小运费。分析:最小费用最大流,最大流的前提下求最小费用。这题我们可以把k种物品分开计算,每次对一种物品进行最小费用最大流计算。如果不分开算会超时。对于每种物品,从源到供应商连接,容量为供应商的储存量,费用为0。采购商到汇连边,容量为需求量,费用为0。供应商到采购商连边,容量为无穷,费用为对应的运费。最小费用最大流的计算流程大致是:每次找到一条根据费用来看的最短路,然后对这条最短路进行增加流量,直到所有路径流量都不能增加为止。V 阅读全文
posted @ 2011-05-17 18:58 undefined2024 阅读(1291) 评论(0) 推荐(0)
摘要: 题意:给定一张图,每个点是一种颜色,用一个单词表示,问是否存在欧拉通路。分析:欧拉路径问题,求是否有欧拉通路1.定理:无向图G有欧拉通路的充分必要条件是G为连通图,并且G仅有两个奇度结点或者无奇度结点。(1)当G是仅有两个奇度结点的连通图时,G的欧拉通路必以此两个结点为端点。(2)当G是无奇度结点的连通图时,G必有欧拉回路。2.一个有向图D具有欧拉通路,当且仅当D是连通的,且除了两个顶点外,其余顶点的入度均等于出度,这两个特殊的顶点中,一个顶点的入度比出度大1,另一个顶点的入度比出度小1.推论:一个有向图D是欧拉图(具有欧拉回路),当且仅当D是连通的,且所有顶点的出度等于入度。3.trie树是 阅读全文
posted @ 2011-05-17 14:05 undefined2024 阅读(1090) 评论(0) 推荐(0)
上一页 1 ··· 150 151 152 153 154 155 156 157 158 ··· 182 下一页