zoukankan      html  css  js  c++  java
  • 洛谷P2031 脑力达人之分割字串

    洛谷P2031 脑力达人之分割字串 

    f[ i ] 表示前 i 个字符最多能分割成几份

    从第 i 位 枚举 模式串 枚举他们是否能够匹配
    能就取 max

     1 #include <bits/stdc++.h>  
     2 #define For(i,j,k) for(int i=j;i<=k;i++) 
     3 using namespace std ; 
     4 
     5 const int N = 311 ; 
     6 char s[N] ; 
     7 int n,L,mx,l ; 
     8 char type[501][N] ; 
     9 int f[N],len[511] ; 
    10 bool flag ; 
    11 
    12 inline int read() 
    13 {
    14     int x = 0 , f = 1 ; 
    15     char ch = getchar() ; 
    16     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
    17     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; } 
    18     return x * f ;  
    19 }
    20 
    21 int main() 
    22 {
    23     scanf("%s",s+1) ; 
    24     n = read() ; 
    25     L = strlen(s+1) ; 
    26     For(i,1,n) scanf("%s",type[ i ]+1) ; 
    27     f[ 0 ] = 0 ; 
    28     For(i,1,L) { 
    29         f[ i ] = mx ; 
    30         For(j,1,n) {
    31             l = strlen(type[ j ]+1) ; 
    32             if( i < l ) continue ; 
    33             flag = 0 ; 
    34             For(k,1,l) if( s[ i-l+k ]!=type[ j ][ k ] ) {
    35                 flag = 1 ; 
    36                 break ; 
    37             }
    38             if(flag) continue ; 
    39             f[ i ] = max( f[ i-l ]+1,f[ i ] ) ; 
    40         }
    41         if( f[ i ] > mx ) mx = f[ i ] ; 
    42     }
    43     //f[ L ] = mx ;  
    44     printf("%d
    ",f[ L ]) ; 
    45     return 0 ; 
    46 }
    47 
    48 
  • 相关阅读:
    Java怎样对一个属性设置set或get方法的快捷键
    小程序怎样控制rich-text中的<img>标签自适应
    Java中Arrys数组常用的方法
    Java 怎样实现调用其他方法
    Java保留两位小数
    解决ajax请求跨域
    rand(7) 到rand(10)
    c++生成随机数
    批量该文件名
    正则表达式(=)
  • 原文地址:https://www.cnblogs.com/third2333/p/7457844.html
Copyright © 2011-2022 走看看