摘要:
完全背包View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxm 50005#define maxn 15int n, m, y;int weight[maxn], value[maxn];int f[maxm];void input(){ scanf("%d%d", &m, &y); scanf( 阅读全文
posted @ 2012-07-10 19:25
undefined2024
阅读(228)
评论(0)
推荐(0)
摘要:
题意:有m层楼,从一层到m层,要进入每层都要打开位于该层的两道门中的至少一道。门锁有2n种,每个门锁为2n种中的一种,可以重复。有2n把钥匙,分别对应2n种锁,但是钥匙两两一组,共n组,每组只能选一个来开门,被选中的可以多次使用,另一个一次都不能用。问最多能上多少层。分析:二分查找能上的层数。每次对于一个确定的层数,也就确定了哪些门需要开。变为一个2-sat问题。其中两两一组的钥匙就是图中的节点。当然图中还需要一些矛盾。矛盾如下,某层有x,y两种锁,x的钥匙a与钥匙b一组,y的要是c与钥匙d一组。如果在某次选了钥匙b,那么本层的x将无法被打开,只能开y,就必须选钥匙c,不能选钥匙d。所以钥匙b 阅读全文
posted @ 2012-07-10 16:32
undefined2024
阅读(934)
评论(0)
推荐(1)
摘要:
题意:给出n个互不相同的数字,要求一个最大的子段,使得该子段内所有数(除了两端以外),值都在两端的数字之间,且不能等于两端的数。分析:先对整个数组分别构造最大值RMQ和最小值RMQ的st数组。然后,枚举子段起点,对于每个起点求出这个起点是区间最小值的最远终点(用二分查找)。然后在这个区间内找到最大值位置,从起点到最大值位置这个区间就是起点所对应的符合题意的最大区间。枚举过所有的起点之后,结果就求出来了。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cs 阅读全文
posted @ 2012-07-10 14:11
undefined2024
阅读(661)
评论(0)
推荐(0)
摘要:
bfsView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxl 50#define maxn 105struct Elem{ int age; char name[maxl];}decendant[maxn];struct Edge{ int v, next, w;}edge[maxn];int n;int head[maxn 阅读全文
posted @ 2012-07-10 10:31
undefined2024
阅读(192)
评论(0)
推荐(0)
摘要:
dp,这一题是没有后效性的,只要在保证了每个子问题时间最少的基础上在追求运送次数最少即可。是不会有运送次数减少了,而时间却增多了的情况的。所以时间最优是次数最优的前提。所以状态转移的时候,只要从自问题的时间最优的情况来,肯定没错。f[i] = max(f[j], arrive_time[i]) + each_time * 2View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define max 阅读全文
posted @ 2012-07-10 09:59
undefined2024
阅读(237)
评论(0)
推荐(0)