zoukankan      html  css  js  c++  java
  • wikioi 1029 中序遍历总数

    题意:给出前序遍历和后序遍历,求总共同拥有多少种中序遍历的可能。

    思路:

    对于一个节点。当且仅当它仅有一棵子树时,在保证先序和后序同样的前提下,才可能有不同的中序(它的子树可在左或右,所以有2种);

    此时必有a[i+1]==b[j-1](为什么)//i是节点在先序中的位置。j是它在后序中的位置;

    因此仅仅要找到这样的节点的个数设为x。ans=2^x。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<set>
    #include<cmath>
    #include<bitset>
    #define mem(a,b) memset(a,b,sizeof(a))
    #define lson i<<1,l,mid
    #define rson i<<1|1,mid+1,r
    #define llson j<<1,l,mid
    #define rrson j<<1|1,mid+1,r
    #define INF 0x7fffffff
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    int main()
    {
        char s[27],ss[27];
        scanf("%s%s",s,ss);
        int i,j,len=strlen(s),rr=strlen(ss),ans=0;
        for(i=0;i<len;i++)
            for(j=0;j<rr;j++)
                if(s[i]==ss[j]&&i>0&&s[i-1]==ss[j+1])
                    ans++;
        ll cnt=1LL<<ans;
        cout<<cnt<<endl;
        return 0;
    }
    


  • 相关阅读:
    windows-DLL注入
    HDU 2148 Score
    HDU 2133 What day is it
    HDU 2112 HDU Today
    HDU 2187 悼念512汶川大地震遇难同胞——老人是真饿了
    HDU 2124 Repair the Wall
    HDU 2117 Just a Numble
    HDU 2114 Calculate S(n)
    HDU 2115 I Love This Game
    HDU 2104 hide handkerchief
  • 原文地址:https://www.cnblogs.com/yxysuanfa/p/6937673.html
Copyright © 2011-2022 走看看