zoukankan      html  css  js  c++  java
  • UVa1362 Exploring Pyramids

    区间dp,枚举走完第一个子树之后回到根节点的位置。 

     1 /*by SilverN*/
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 #include<vector>
     8 using namespace std;
     9 const int mod=1e9;
    10 const int mxn=310;
    11 int read(){
    12     int x=0,f=1;char ch=getchar();
    13     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    14     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    15     return x*f;
    16 }
    17 char s[mxn];
    18 int f[mxn][mxn];
    19 int main(){
    20     int i,j;
    21     while(scanf("%s",s+1)!=EOF){
    22         int n=strlen(s+1);
    23         memset(f,0,sizeof f);
    24         for(i=1;i<=n;i++)f[i][i]=1;
    25         for(int st=2;st<=n;st++){
    26             for(i=1;i<=n;i++){
    27                 j=i+st-1;if(j>n)break;
    28                 if(s[i]==s[j]){
    29                     for(int k=i+2;k<=j;k++){
    30                         if(s[k]==s[i]){
    31                             f[i][j]=((long long)f[i][j]+((long long)f[i+1][k-1]*f[k][j])%mod)%mod;
    32                         }
    33                     }
    34                 }
    35             }
    36         }
    37         printf("%d
    ",f[1][n]);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    jmeter工具应用1
    django1
    5.自动化测试模型
    4.清除cookie操作
    2.操作浏览器
    3.8种元素定位
    1.介绍与环境安装
    模块
    urllib库
    自动化测试PO模式
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6283192.html
Copyright © 2011-2022 走看看