You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 5010 ;
/**
* 功能:高精度加法模板
* @param A
* @param B
* @return
*/
vector < int > add ( vector < int > & A , vector < int > & B ) {
if ( A . size ( ) < B . size ( ) ) return add ( B , A ) ;
int t = 0 ;
vector < int > C ;
for ( int i = 0 ; i < A . size ( ) ; i + + ) {
t + = A [ i ] ;
if ( i < B . size ( ) ) t + = B [ i ] ;
C . push_back ( t % 10 ) ;
t / = 10 ;
}
if ( t ) C . push_back ( t ) ;
return C ;
}
vector < int > A , B , C ;
int main ( ) {
int n ;
cin > > n ;
if ( n < = 2 ) {
printf ( " %d " , n ) ;
return 0 ;
}
//初始化一阶台阶步数
A . push_back ( 1 ) ;
//初始化二阶台阶步数
B . push_back ( 2 ) ;
//以后每阶台阶, 都是可以从i-1,i-2阶台阶迁移过来, 方法数就是两者的和
for ( int i = 3 ; i < = n ; i + + ) {
C = add ( A , B ) ;
//A<---B 方便下次计算
A . assign ( B . begin ( ) , B . end ( ) ) ;
//B<---C 方便下次计算
B . assign ( C . begin ( ) , C . end ( ) ) ;
}
//倒序输出结果
for ( int i = B . size ( ) - 1 ; i > = 0 ; i - - )
printf ( " %d " , B [ i ] ) ;
return 0 ;
}