Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- #include <iterator>
- using namespace std;
- const int INF = (int)(2e9);
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define mp make_pair
- #define files freopen("secretroom.in", "rt", stdin); freopen("secretroom.out", "wt", stdout)
- int main()
- {
- ull n, k;
- cin >> n >> k;
- vector<ull> dpz(n+1, 0);
- vector<ull> dpzn(n+1, 0);
- dpz[2] = k - 1;
- dpzn[2] = (k - 1)*k - k + 1;
- for (int i = 3; i <= n; i++)
- {
- dpz[i] = dpzn[i - 1];
- dpzn[i] = (dpz[i - 1] + dpzn[i - 1])*(k - 1);
- }
- cout << dpz[n] + dpzn[n];
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment