50分求调

P1255 数楼梯

XY_1_SunRuiChen @ 2025-01-15 17:23:03

50分,5TLE求调

#include<bits/stdc++.h>
using namespace std;
int tj(int n){
    int c;
    if(n == 1) c = 1;
    else if(n == 2) c = 2;
    else{
        c = tj(n - 1) + tj(n - 2);
    }
    return c;
}
int main(){
    int n;
    cin >> n;
    if(n == 0) {
        cout << 0;
        return 0;
    }
    cout << tj(n);
    return 0;
}

by wzy_ok @ 2025-01-15 18:53:56

@XY_1_SunRuiChen 注意一下数据:对于 100% 的数据, 1≤N≤5000。


|