NOIP2015其余几道题
2015-11-10 19:42
295 查看
T1:
View Code
#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
相关文章推荐
- HttpURLConnection get post 方式请求 (笔记)
- 【算法】输出斐波那契数列任意一位的值得算法
- Play框架中集成Swagger
- 7、类的扩展
- MTK Android G-Sensor auto detect源码分析
- crontab简易入门
- Android快速SDK(8)毛玻璃效果BlurView【傻瓜模式】
- 黑马程序员——基础知识——线程间的通信
- python数据结构---栈和队列
- 初学杂烩——第四章
- 服务器端tomcat,debug调试
- 欢迎使用CSDN-markdown编辑器
- OC-id、构造方法
- Java语言程序设计基础篇第八版个人笔记(z2015年11月10日19:39:39)
- String, StringBuffer, StringBuilder
- 项目冲刺-第一天
- Linux性能调优
- Finding outliers in numerical data
- 丧病的期中考
- JavaScript正则表达式应用---replace()