Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int rec (int n ,int m, vector<vector<int>>& a)
  5. {
  6. if (a[n][m]!=0)
  7. {
  8. return a[n][m];
  9. }
  10. if (n==0)
  11. {
  12. a[n][m]=rec(n,m-1,a);
  13. }
  14. else if (m==0)
  15. {
  16. a[n][m]=rec(n-1,m,a);
  17. }
  18. else
  19. {
  20. a[n][m]= rec(n-1,m,a)+rec(n,m-1,a)+rec(n-1,m-1,a);
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int m;
  27. int n;
  28. cin >>m;
  29. cin>>n;
  30. vector <vector<int>>a(n);
  31. for (int i=0;i<n;i++)
  32. {
  33. a[i].resize(m);
  34. }
  35. a[0][0]=1;
  36. rec(n-1,m-1,a);
  37. cout << a[n-1][m-1]<< endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement