50分

P1255 数楼梯

_Glassy_Sky_ @ 2023-01-03 10:17:25

#include<bits/stdc++.h>
using namespace std;
int a[5005];
int main()
{
    int n;
    cin >> n;
    a[0] = a[1] = 1;
    for(int i = 2; i <= n; i ++)
        a[i] = a[i - 1] + a[i - 2];
    cout << a[n];
    return 0;
}

小学奥数的方法


by Hongzixuan0922 @ 2023-01-03 10:40:54

但是可以用Python


by Hongzixuan0922 @ 2023-01-03 10:44:15

n = int(input())
a=1
b=1
n-=1
if n>0:
    while n>0:
        c=a+b
        a=b
        b=c
        n-=1
    print(b)
elif n==0:
    print(1)
else:
    print(0)

by Mystic_dragon @ 2023-01-20 11:13:29

@FZwangmuem 要用高精度


上一页 |