50分,记忆化递归

P1255 数楼梯

ansan @ 2023-12-16 21:15:13


#include<bits/stdc++.h>
using namespace std;
int a[5001];
int louti(int n){
    if(a[n] != 0) 
    return a[n];
    else if(n == 1)
    return 1;
    else if(n == 2)
    return 2;
    else
    return a[n] = louti(n-1)+louti(n-2);//记忆化递归 
}
int main(){
    int n, count = 0, i, j;
    cin >> n;
    count = louti(n);
    cout << count;
    return 0;
}

by No_Rest @ 2023-12-16 21:19:07

要高精度的


|