chillurbrain

3. К-ичные числа

May 22nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. pair<int,int> a[20][20];
  5. int k,n;
  6. int main()
  7. {
  8. int i,j;
  9. cin>>n>>k;
  10. if(n==1)
  11. {
  12. cout<<k<<endl;
  13. return 0;
  14. }
  15. for(i=2;i<=k;i++)
  16. a[1][i].first=i-1;
  17. for(i=2;i<=n;i++)
  18. for(j=2;j<=k;j++)
  19. {
  20. a[i][j].second=a[i-1][j].first;
  21. a[i][j].first=(a[i-1][j].first+a[i-1][j].second)*(j-1);
  22. }
  23. cout<<a[n][k].first+a[n][k].second<<endl;
  24. return 0;
  25. }
Add Comment
Please, Sign In to add comment