我这个超时了,请问有什么解决方法

P1255 数楼梯

蒟蒻QWQ2008 @ 2021-02-14 18:43:29

#include<cstdio>
#include<iostream>
#include <algorithm>
using namespace std;
int n;
int cnt=0;
void dfs(int cur,int res)
{
    if(res>=cur)
    {
        cnt++;
        return ;
    }
    dfs(cur,res+1);
    dfs(cur,res+2);
}
int main()
{
    cin>>n;
    dfs(n,1);
    cout<<cnt;
}

by Implicit @ 2021-02-14 18:44:50

@蒟蒻QWQ2008

  1. 加高精
  2. 加记忆化

by _caiji_ @ 2021-02-14 18:45:16

记忆化。

还有,这题需要高精度。


by _Empty @ 2021-02-14 18:46:00

猪也爽铁


by EuphoricStar @ 2021-02-14 18:46:31

看标签:斐波那契数列


by 蒟蒻QWQ2008 @ 2021-02-14 18:51:10

怎么记忆化?


by BMTXLRC @ 2021-02-14 18:53:24

@蒟蒻QWQ2008 别打搜索,容易炸,打DP最好了


by LYNiko @ 2021-02-15 11:46:46

要用高精度+斐波那契数列做


|