链接:
https://www.nowcoder.com/questionTerminal/1843c3b052984e3f98c68935ea3c0d79?orderByHotValue=1&page=1&onlyReference=false
来源:牛客网
某种特殊的数列a1, a2, a3, …的定义如下:a1 = 1, a2 = 2, … , an = 2 * an − 1 + an - 2 (n > 2)。
给出任意一个正整数k,求该数列的第k项模以32767的结果是多少?
#include
using namespace std;
const int maxn = 32768;
long long dp[maxn] = { 0 };
long long Fabnic(int n)
{
if (n == 1)
{
return 1;
}
if (n == 2)
{
return 2;
}
if (dp[n] != 0)
{
return dp[n];
}
dp[n] = (2 * Fabnic(n - 1) + Fabnic(n - 2)) % 32767;
return dp[n];
}
int main()
{
int n;
int a;
while (cin >> n)
{
for (int i = 0; i> a;
cout << Fabnic(a) << endl;
}
}
return 0;
}