#21702: 求救


s10806226@smail.ycsh.tp.edu.tw (Eri)

學校 : 臺北市立永春高級中學
編號 : 108040
來源 : [101.3.116.101]
最後登入時間 :
2022-05-11 14:14:13

#include <bits/stdc++.h>

 

using namespace std;

 

unsigned long long int f(unsigned long long int x){

    if(x==0)return 1;

    else if(x==1)return 3;

    else return 2*f(x-1)+f(x-2);

}

 

int main()

{

    unsigned long long int n;

    cin>>n;

    cout<<f(n)<<"\n";

    return 0;

}

 

n=50跑不出來

 

#21703: Re:求救


s10806226@smail.ycsh.tp.edu.tw (Eri)

學校 : 臺北市立永春高級中學
編號 : 108040
來源 : [101.3.116.101]
最後登入時間 :
2022-05-11 14:14:13

#include <bits/stdc++.h>

 

using namespace std;

 

unsigned long long int f(unsigned long long int x){

    if(x==0)return 1;

    else if(x==1)return 3;

    else return 2*f(x-1)+f(x-2);

}

 

int main()

{

    unsigned long long int n;

    cin>>n;

    cout<<f(n)<<"\n";

    return 0;

}

 

可以跑出來 但會TLE

 



#21725: Re:求救


s10806226@smail.ycsh.tp.edu.tw (Eri)

學校 : 臺北市立永春高級中學
編號 : 108040
來源 : [101.3.116.101]
最後登入時間 :
2022-05-11 14:14:13

#include <bits/stdc++.h>

 

using namespace std;

 

unsigned long long int f(unsigned long long int x){

    if(x==0)return 1;

    else if(x==1)return 3;

    else return 2*f(x-1)+f(x-2);

}

 

int main()

{

    unsigned long long int n;

    cin>>n;

    cout<<f(n)<<"\n";

    return 0;

}

 

可以跑出來 但會TLE

 

 

沒事 解決了