Advertisement
Guest User

assignment2

a guest
Oct 18th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int combinationWithRepeatation1(int a, int b){
  6.     int n=a, k=b;
  7.     if(n==1)return 1;
  8.     if(k==1)return n;
  9.     int totalWays=0;
  10.     for(k; k>=0; k--){
  11.         totalWays+=combinationWithRepeatation1(n-1, k);
  12.  
  13.     }
  14.     return totalWays;
  15.  
  16. }
  17. int combinationWithRepeatation2(int a, int b){
  18.     int n=a, k=b;
  19.     if(n==1)return 1;
  20.     if(k==1)return n;
  21.     int totalWays=0;
  22.     totalWays+=combinationWithRepeatation2(n-1,k)+combinationWithRepeatation2(n,k-1);
  23.     return totalWays;
  24. }
  25. int main()
  26. {
  27.     int n=combinationWithRepeatation2(3,5);
  28.     cout<<n;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement