top1编程
← 返回题目
题解

爬楼梯

1 条题解

  • 0
    @ 2026-7-28 22:45:18
    #include<bits/stdc++.h>
    using namespace std;
    int f(int k)//求走k级楼梯的走法数
    {
        if(k <= 2)
            return k;
        return f(k-1) + f(k-2);
    }
    int main() 
    {
        int n;
        while(cin >> n)
            cout << f(n) << endl;      
    	return 0;
    }
    
    • 1