UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194811#4. 爬楼梯Happysheep1001ms1336kbC++793b2023-10-18 08:25:512023-10-18 08:25:52

answer

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int n,len=1,f[5003][5003];//f[k][i]--第k阶台阶所对应的走法数 
void hp(int k)//高精度加法,k来存阶数 
{    
    int i;
    for(i=1;i<=len;i++)
     f[k][i]=f[k-1][i]+f[k-2][i];//套用公式 
    for(i=1;i<=len;i++)             //进位 
     if(f[k][i]>=10)
     {
         f[k][i+1]+=f[k][i]/10;
         f[k][i]=f[k][i]%10;
         if(f[k][len+1])len++;
    }
}
int main()
{
    int i;
    scanf("%d",&n);
    f[1][1]=1; f[2][1]=2;         //初始化 
    for(i=3;i<=n;i++)              //从3开始避免越界 
     hp(i);                         
    for(i=len;i>=1;i--)             //逆序输出 
     printf("%d",f[n][i]);
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1336kb

input:

36

output:

24157817

result:

ok 1 number(s): "24157817"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1312kb

input:

30

output:

1346269

result:

ok 1 number(s): "1346269"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1304kb

input:

29

output:

832040

result:

ok 1 number(s): "832040"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1272kb

input:

21

output:

17711

result:

ok 1 number(s): "17711"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1252kb

input:

16

output:

1597

result:

ok 1 number(s): "1597"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1240kb

input:

12

output:

233

result:

ok 1 number(s): "233"

Test #7:

score: 10
Accepted
time: 0ms
memory: 1224kb

input:

9

output:

55

result:

ok 1 number(s): "55"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #9:

score: 10
Accepted
time: 1ms
memory: 1204kb

input:

4

output:

5

result:

ok 1 number(s): "5"

Test #10:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

1

output:

1

result:

ok 1 number(s): "1"