递推式:f[n]=2*f[n-2]+f[n-1]

#include <cstdio>
#include <iostream>
using namespace std;
long long f[51];
int main()
{
    int i,n;
    f[1]=1; f[2]=3;
    for(int i=3; i<51; i++)
    f[i]=f[i-1]+2*f[i-2];
    cin>>n;
    while(cin>>n) cout<<f[n]<<endl;
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2018-07-13
  • 2021-08-30
  • 2022-12-23
  • 2021-11-16
猜你喜欢
  • 2021-11-05
  • 2022-12-23
  • 2021-06-10
  • 2022-02-20
  • 2021-06-22
  • 2021-12-18
  • 2022-02-02
相关资源
相似解决方案