Advertisement
Zuneve

without00

Sep 14th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int n, k;
  8. cin >> n >> k;
  9. vector <int> fp(n+1);
  10. if (n==1) cout << k;
  11. else{
  12. fp[0]=k-1;
  13. fp[1]=fp[0]*k;
  14. for (int i = 2; i<n; i++) {
  15. fp[i]=(k-1)*(fp[i-1]+fp[i-2]);
  16. }
  17. } cout << fp[n-1];
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement