zoukankan      html  css  js  c++  java
  • NOIP 2015 子串

    借鉴大神思路。。。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cstdlib>
     4 #include<iostream>
     5 #include<queue>
     6 #include<stack>
     7 #include<cmath>
     8 #include<algorithm>
     9 #include<malloc.h>
    10 using namespace std;
    11 #define clc(a,b) memset(a,b,sizeof(a))
    12 #define inf 0x3f3f3f3f
    13 const int N=10010;
    14 #define LL long long
    15 const double eps = 1e-5;
    16 const double pi = acos(-1);
    17  int g[1010][1010];
    18 // inline int r(){
    19 //     int x=0,f=1;char ch=getchar();
    20 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
    21 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    22 //     return x*f;
    23 // }
    24  const LL mod = 1000000007;
    25 int f[2][1010][210];
    26 int tem[2][1010][210];
    27 char s1[1010],s2[1010];
    28 int main(){
    29     // freopen("in.txt","r",stdin);
    30     int n,m,K;
    31     scanf("%d%d%d",&n,&m,&K);getchar();
    32     scanf("%s",s1+1);getchar();
    33     scanf("%s",s2+1);
    34     f[0][0][0]=1,tem[0][0][0]=1;
    35     for(int i=1;i<=n;i++){
    36         tem[0][i][0]=1;
    37     }
    38     for(int k=1;k<=K;k++){
    39         clc(tem[k&1],0);
    40         clc(f[k&1],0);
    41         for(int i=1;i<=n;i++){
    42              for(int j=1;j<=m;j++){
    43                 if(s1[i]==s2[j]){
    44                     f[k&1][i][j]=tem[(k-1)&1][i-1][j-1]%mod;
    45                     if(s1[i-1]==s2[j-1]){
    46                         f[k&1][i][j]=(f[k&1][i][j]+f[k&1][i-1][j-1])%mod;
    47                     }
    48                 }
    49                 tem[k&1][i][j]=(tem[k&1][i][j]+f[k&1][i][j]+tem[k&1][i-1][j])%mod;
    50              }
    51         }
    52     }
    53     int ans=0;
    54     for(int i=1;i<=n;i++){
    55         ans=(ans+f[K&1][i][m])%mod;
    56     }
    57     printf("%d
    ",ans);
    58     return 0;
    59 }
    View Code
  • 相关阅读:
    phpcms基础
    读取数据库有的设置选中状态
    用php 生成 excel 表格
    ajax验证用户名是否存在,手机号是不是匹配
    系统登陆简单的密码验证
    分页显视
    时间选择的三级连动 年,月,日
    session控制登入权限
    jQuery, js 验证两次输了密码的一相同
    正则表达式判断手机号是否11位数字
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5425902.html
Copyright © 2011-2022 走看看