6TLE,1WA,求助

P1255 数楼梯

蒟蒻QWQ2008 @ 2020-07-01 15:37:39

#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 e_32767 @ 2020-07-01 15:49:37

if(res>=cur)

这里是不是不能大于呀...


by e_32767 @ 2020-07-01 15:49:49

@蒟蒻QWQ2008


by e_32767 @ 2020-07-01 15:51:02

至于TLE我还不知道


by jiangby @ 2020-07-01 17:37:36

你这复杂度明显有问题好吧,建议去看题解


by SIXIANG32 @ 2020-07-01 17:44:21

这……看看样例不就知道是肺部垃圾吗?


|