方法一:
dp[i+1] = 2*dp[i]+(-1)^(i+1), (i = 1, 2 …)
方法二:
dp[i]=dp[i-1]+dp[i-2]*2 (i>=3)
这题数据量也不大,简单打表AC
#include <iostream>
using namespace std;
int main()
{
int a[] = {1,3,5,11,21,43,85,171,341,683,
1365,2731,5461,10923,21845,
43691,87381,174763,349525,699051,
1398101,2796203,5592405,11184811,22369621,
44739243,89478485,178956971,357913941,715827883};
int n, i;
cin>>n;
while(n--){
cin>>i;
cout<<a[i-1]<<endl;
}
return 0;
}