View Code #include<cstdio>#include<cstring>int n,m;int a[1000010],b[10010];int p[11111];void getp(){ p[1]=0; int i,j=0; for(i=2;i<=m;i++){ while(j>0&&b[j+1]!=b[i]) j=p[j]; if(b[j+1]==b[i]) j+=1; p[i]=j; }}int kmp(){ int i,j=0,cnt=0; for(i=1;i<=n;i++){ wh... Read More
posted @ 2012-01-01 18:37
Because Of You
Views(450)
Comments(0)
Diggs(0)
核心思想:当某个字符失配时,尽可能多的向右滑动而又不影响结果。具体见http://www.matrix67.com/blog/archives/115/View Code #include<cstdio>#include<cstring>int n,m;char a[1000],b[1000];int p[1000];void getp(){ p[1]=0; int i,j=0; for(i=2;i<=m;i++){ while(j>0&&b[j+1]!=b[i]) j=p[j]; if(b[j+1]==b[i]) j+=1; p[i... Read More
posted @ 2012-01-01 18:21
Because Of You
Views(629)
Comments(0)
Diggs(0)
View Code #include<cstdio>#include<cstring>const int maxn = 50010;int c[maxn];int lowbit(int x){ return x&-x;}void update(int x,int d){ for(;x<=maxn;x+=lowbit(x)) c[x]+=d;}int query(int x){ int sum=0; for(;x>0;x-=lowbit(x)) sum+=c[x]; return sum;}int main(){ int t,n,... Read More
posted @ 2012-01-01 17:42
Because Of You
Views(273)
Comments(0)
Diggs(0)
注释在代码中两个树状数组,或者用两次第一次维护的是空位的位置,update,更新管辖范围内空位的个数,getk获得第k个空位置的个数,其实就是第k小数,然后占据该位置,更新相应信息第二次维护的是最长不下降子序列的长度,update:更新长度,getm:获得当前位置之前的最长的LIS长度,再把当前的数加进末尾View Code #include<stdio.h>#include<string.h>#define lowbit(i) (i&(-i))const int MAXN=100005;const int MAXLOG=17;int B[MAXN],pos[M Read More
posted @ 2012-01-01 09:32
Because Of You
Views(596)
Comments(0)
Diggs(0)