Advertisement
SergeyPGUTI

10.1.3

Apr 4th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int Ncnt2(int N,int K);
  6.  
  7. int Ncnt(int N,int K) //не можем ставить 0
  8. {
  9.     if (N==1) return K-1;
  10.   return (K-1)*Ncnt2(N-1,K);
  11. }
  12. int Ncnt2(int N,int K) //можем ставить 0
  13. {
  14.     if (N==1) return K;
  15.     return (K-1)*Ncnt2(N-1,K)+Ncnt(N-1,K);
  16. }
  17.  
  18. int main()
  19. {
  20.  
  21.     int N,K;
  22.     cin>>N>>K;
  23.     cout<<Ncnt(N,K);
  24.     return 0;
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement