上一页 1 ··· 54 55 56 57 58 59 60 61 62 ··· 182 下一页
摘要: dpView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 205#define maxm 2005#define inf 0x3f3f3f3fint n, m;char st[maxm];int cost[maxn];int f[maxm][maxm];void input(){ scanf("%d%d", &n, &m); scanf( 阅读全文
posted @ 2012-07-05 15:51 undefined2024 阅读(241) 评论(0) 推荐(0)
摘要: bfsView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxc 105#define maxn 1005#define maxm 10005struct Edge{ int v, next;} edge[maxm];int cow, n, m;int head[maxn];int ncount;bool vis[maxn];int reach[maxn];int q[maxn] 阅读全文
posted @ 2012-07-05 14:14 undefined2024 阅读(124) 评论(0) 推荐(0)
摘要: 后缀数组+单调队列注意:后缀数组的所有后缀中包括空串,因此有strlen(s)+1个后缀。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define N 20005struct Elem{ int pos, value; Elem() {} Elem(int pp, int vv): pos(pp), value(vv) {}}q[N];int n, m;int s[N];// N > 阅读全文
posted @ 2012-07-05 13:52 undefined2024 阅读(482) 评论(0) 推荐(0)
摘要: 题意:给定一个无向图,要从1点到n点再返回1点,每条边最多走一次,问最短需要走多远。分析:最小费用最大流,把题意看成是要找两条无交集的从1到n的路线,使距离和最小。图中的点和边就是网络流图中的点和边。设置一个源,接到1点,设置一个汇,从n点接到汇。为保证无交集,我们把每条边的流量设置为1,而源发出的流量和汇接收的流量均为2。每条边的费用就是该边在原图中的权值。注意:有重边,所以要用邻接表。因为是无向图,所以要在加边时,原图中的一条边要变成网络流图中的两条边(如果把反向负权费用边也算上就总共4条边)。由于最短路算法是最小费用最大流算法的子算法,所以有些最短路的题可能要用到最小费用最大流。View 阅读全文
posted @ 2012-07-05 10:45 undefined2024 阅读(2624) 评论(0) 推荐(1)
摘要: 二分法有些能用动态规划求解但是超时的题目,可以考虑二分法。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 100005#define inf 0x3f3f3f3fint n, cow;int pos[maxn];void input(){ scanf("%d%d", &n, &co 阅读全文
posted @ 2012-07-05 09:21 undefined2024 阅读(683) 评论(0) 推荐(0)
上一页 1 ··· 54 55 56 57 58 59 60 61 62 ··· 182 下一页