您的位置:首页 > 其它

NOIP2015其余几道题

2015-11-10 19:42 295 查看
T1:

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
typedef unsigned int ll;
const int maxn=1010;
const int maxm=210;
const int mod=1000000007;
char A[maxn],B[maxm];
int n,m,k,mx[maxn][maxm];
ll f[2][maxn][maxm],g[2][maxn][maxm];
int match(int x,int y) {
int ans=0;
while(x>ans&&y>ans&&A[x-ans]==B[y-ans]) ans++;
return ans;
}
void update(ll& ans,ll v) {
ans=v;if(ans>mod) ans-=mod;
}
int main() {
n=read();m=read();k=read();
scanf("%s%s",A+1,B+1);
rep(i,1,n) rep(j,1,m) mx[i][j]=match(i,j);
int cur=0;
rep(i,0,n) rep(j,0,n-i) g[0][i+j][j]=1;
rep(t,1,k) {
cur^=1;
memset(g[cur],0,sizeof(g[cur]));
rep(gap,0,n) rep(i,gap+t,min(n,m+gap)) {
int j=i-gap;
if(j-mx[i][j]-1<0) f[cur][i][j]=g[cur^1][i-1][j-1];
else {
int temp=j-mx[i][j]-1;if(temp<t-2) temp=t-2;
update(f[cur][i][j],g[cur^1][i-1][j-1]-g[cur^1][temp+gap][temp]+mod);
}
update(f[cur][i][j],f[cur][i][j]+f[cur][i-1][j]);
if(j>t) update(g[cur][i][j],f[cur][i][j]+g[cur][i-1][j-1]);
else g[cur][i][j]=f[cur][i][j];
}
}
printf("%u\n",f[cur]
[m]);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: