Advertisement
CosminVarlan

Combinari cu programare dinamica

Apr 3rd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[200][200];
  6.  
  7. int c1(int n, int k) // doar cu recursivitate
  8. {
  9.     if ((k==0) || (n==k)) return 1;
  10.     else return c1(n-1,k-1)+c1(n-1,k);
  11. }
  12.  
  13.  
  14. int c2(int n, int k) // cu programare dinamica
  15. {
  16.     if ((k==0) || (n==k)) a[n][k]=1;
  17.     else
  18.     {
  19.         if (!a[n-1][k-1]) c2(n-1,k-1);
  20.         if (!a[n-1][k]) c2(n-1,k);
  21.         a[n][k]=a[n-1][k]+a[n-1][k-1];
  22.     }
  23.     return a[n][k];
  24. }
  25.  
  26.  
  27.  
  28. int main()
  29. {
  30.     cout << c1(30,15) << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement