[Group] 03NOIP popularity stack (Informatics Olympiad one through 1924) (Luo Gu 1044)

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,ans,m,k,ans2;
 4 int a[51],f[51],d[51][51],num[51][51],tmp[51],s[51];
 5 int read()
 6 {
 7     char c;int ff=1;
 8     while((c=getchar())<'0'||c>'9')
 9         if(c=='-')ff=-1;
10     int num=c-'0';
11     while((c=getchar())>='0'&&c<='9')
12         num=num*10+c-'0';
13     return ff*num;
14 }
15 void write(int x)
16 {
17     if(x<0)
18     {
 . 19          the putchar ( ' - ' );
 20 is          X = - X;
 21 is      }
 22 is      IF (X> . 9 ) Write (X / 10 );
 23 is      the putchar (X% 10 + ' 0 ' );
 24 } // read optimization and output optimization is a good habit! (▽ to ¯ ¯) / 
25  int main ()
 26 is  {
 27      n-= Read (); F [ 0 ] = . 1 ;
 28      for ( int I = . 1 ; I <= n-; I ++ )
29          for ( int J = 0 ; J <I; J ++ )
 30              F [I] = F + [J] * F [IJ- . 1 ]; // recursive: time complexity of O (n2) space complexity of O ( n-) 
31 is      Write (F [n-]);
 32      return  0 ;
 33 is   }

 

Accidentally code first posted up ... ying ...

dalao we will look forward to it ...

I jiao have written the following ☟☟☟ this silver really good! !

noip03 popular group "stack" Depth - Baidu library https://wenku.baidu.com/view/7c645d5e3b3567ec102d8a34.html?tdsourcetag=s_pcqq_aiomsg&qq-pf-to=pcqq.c2c


 

Description [title]

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., pop (pop up from a stack element) and a push (a 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.

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

We can now carry out two operations,

1. a number, the head end moves from the operand stack sequence heads (corresponding to a push operation of the stack data structure)

2. a number, from the head end of the stack is moved to the output of the trailing end of the sequence (corresponding to the data structure of the stack pop operation)

Using these two operations, a number of the sequence of operations can be obtained a series of output sequence, the process 123 generates a sequence of 231 as shown by the FIG. (Original state as shown above)

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

[Enter]

It contains only one integer n (1≤n≤18)

[Output]

Only one line, i.e., the total number of possible output sequences

[Sample input]

3

[Sample Output]

5

Guess you like

Origin www.cnblogs.com/ljy-endl/p/11305819.html