luogu P1044 stack

Topic background

The stack is a data structure in the classic computer, simply, the stack is limited to the insertion end of the linear table delete operation.

There are two most important stack operation, i.e. poppop (a pop from the stack element) and pushpush (one push element).

The importance of the stack without saying that any one course will introduce stack data structure. Ningning students in the basic concepts review the stack, think of a book on the issue is not talked about, but he could not give an answer, so they need your help.

Title Description

Nene contemplated that such a problem: the number of a sequence of operations, 1,2, ..., n1,2, ..., n (illustrated as Case 1 to 3), is greater than the depth of the stack AA nn.

We can now carry out two operations,

A number, the head end moves from the operand stack sequence heads (corresponding to the operation of the data structure stack pushpush)

A number, from the head end of the stack is moved to the output of the trailing end of the sequence (corresponding to the operation of the data structure stack poppop)

Using these two operations, a number of the sequence of operations can be obtained a series of output sequence, as shown below by generating a series of processes 123,123 to 231,231.

(Original state as shown above)

Will, ..., n1,, ... The number of your program given NN, calculated by the operator and outputs the number sequence 1, 2, through the operation of the output sequence n may be obtained.

Flood problem

Cattleya find the number of stack scheme

#include<cstdio>
#include<iostream>
using namespace std;
const int N=115,mod=100;
#define int long long
int dp[N];
signed main(){
    int n;
    cin>>n;
    dp[0]=1;dp[1]=1;dp[2]=2;
    for(int i=3;i<=n;i++){
        int j=0;
        while(j<=i-1){
            dp[i]+=dp[j]*dp[i-j-1];
            j++;
        }
    }
    cout<<dp[n]<<endl;
}

Guess you like

Origin www.cnblogs.com/naruto-mzx/p/11726512.html