上一页 1 ··· 169 170 171 172 173 174 175 176 177 ··· 182 下一页
摘要: 题意:给定一个数列,要求把数列切分成m个段,使得总和最大的一段的总和最小。求这个总和。分析:只知道dp的方法,但是超时。后来知道是二分。就是二分查找一个阶段消费的上限(总和)。每次可以用O(n)的效率来判断这个值是不是符合。我们要找的就是符合条件的最小值。View Code #include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>usingnamespace std;#define maxn 100005int n, m, f[maxn], l, r, mid 阅读全文
posted @ 2011-02-22 16:31 undefined2024 阅读(1137) 评论(2) 推荐(0)
摘要: 又犯了同样的错误,开edge数组开小了,应该是maxm,开成了maxn正反两个图,进行两次dijkstra即可View Code #include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>using namespace std;#define maxn 1005#define maxm 100005#define inf 1000000000struct Edge{ int v, w, next;}edge[maxm], opedge[maxm];int n, 阅读全文
posted @ 2011-02-22 15:42 undefined2024 阅读(221) 评论(0) 推荐(0)
摘要: 利用priority_queue模拟霍夫曼树。注意结果要用long long.View Code #include #include #include #include #include usingnamespace std;struct Integer{ longlong x; Int... 阅读全文
posted @ 2011-02-22 15:41 undefined2024 阅读(213) 评论(0) 推荐(0)
摘要: 利用栈进行动态规划,要注意的地方是总和得用longlong因为80000^2是超出int范围的。View Code 阅读全文
posted @ 2011-02-22 11:14 undefined2024 阅读(397) 评论(0) 推荐(0)
摘要: 题意:给出矩阵A,求S = A + A2 + A3 + … + Ak分析:把问题转化以加速,令B =A I0 I则B^(k + 1) = A^(k + 1) I + A + A2 + A3 + … + Ak 0I用二分法求B^(k + 1)View Code #include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>usingnamespace std;#define maxn 61struct Matrix{ int ma[maxn][maxn];} b, a 阅读全文
posted @ 2011-02-21 21:34 undefined2024 阅读(1170) 评论(0) 推荐(1)
上一页 1 ··· 169 170 171 172 173 174 175 176 177 ··· 182 下一页