This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1000000007;
ll dp[1000005];
ll solve(int n, int k) {
if(n == 0) return 1;
if(n == 2) return k;
if(dp[n]) return dp[n];
// (s)
ll ret = k*solve(n-2, k);
ret %= MOD;
// ()s()
if(n >= 4) {
ret += k*solve(n-4, k);
ret %= MOD;
}
dp[n] = ret;
return ret;
}
void solve() {
int n, k;
cin >> n >> k;
cout << solve(2*n, k) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |