今年学士は11ではありません
パソコン単一の最も迷惑な事は11月11日である私たちはシングルスと呼んでいます。
彼が存在する場合、PCは非常に悲しいだろう、そこにある「11」をすべてを見たいと思っていませんでした
プライマリ弟の日01は、長さの文字列を与えたN PC、パソコンプライマリ弟は悲しい望んでいません。
今、あなたは長さnは、PCの種類は、(数が多くなるので、1E9 + 7を法の最終結果があります)01の悲しい文字列をさせませんどのように多くの計算ヘルプ小学校の兄に持ちます。
説明を入力します。
1の整数≤N≤1E6
出力説明:
結果を表す整数。
ソリューション:
長い時間のためのデジタルDPタイトルは、ビットさびを書いていない、配列はそれを話すことはありません、コード内でDPコメントが定義されています
#include <bits/stdc++.h>
#define DEBUG puts("------------")
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
ll dp[N][3];
const int mod = 1e9 + 7;
ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
b >>= 1;
a = a * a % mod;
}
return res % mod;
}
int main()
{
#ifdef DEBUG
ios::sync_with_stdio(0);
#endif // DEBUG
//数位DP
//dp[i][0]:长度为i末尾已经有连续0个1 并且不含有两个连续的1
//dp[i][1]:长度为i末尾已经有连续1个1 并且不含有两个连续的1
//dp[i][2]:长度为i有两个1
//转移:dp[i][0] 可以有dp[i-1][0]和dp[i-1][1]末尾加一个0
//dp[i][1]可以由dp[i-1][0]末尾加一个1
//dp[i][2]就是dp[i-1][2]后面随便加0或者1,也就是dp[i-1][2] * 2以及dp[i-1][1]加一个1
dp[1][0] = 1;
dp[1][1] = 1;
dp[1][2] = 0;
for (int i = 2; i <= 1000000; i++) {
dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
dp[i][1] = dp[i - 1][0];
dp[i][2] = dp[i - 1][2] * 2 + dp[i - 1][1];
dp[i][0] %= mod;
dp[i][1] %= mod;
dp[i][2] %= mod;
}
int n;
cin >> n;
ll res = qpow(2, n);
res -= dp[n][2];
res = (res + mod) % mod;
cout << res << "\n";
return 0;
}