fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef vector<ll> vi;
  6. typedef vector<long long> vl;
  7. #define pb push_back
  8. #define ff first
  9. #define ss second
  10. #define forn(n) for (ll i = 0; i < n; i++)
  11. #define forc(cn, abc) ((cn).find(abc) != (cn).end())
  12. #define yes cout << "YES\n";
  13. #define no cout << "NO\n";
  14. #define all(a) a.begin(), a.end()
  15. #define rall(a) a.rbegin(), a.rend()
  16. #define poin(x) cout << fixed << setprecision(x);
  17.  
  18. vector<ll> dp(35);
  19. ll combination(ll n, ll r)
  20. {
  21. if (n == r)
  22. return 1;
  23.  
  24. if (r == 1)
  25. return n;
  26.  
  27. return dp[n] = combination(n - 1, r) + combination(n - 1, r - 1);
  28. }
  29. void solve()
  30. {
  31. ll n, r;
  32. cin >> n >> r;
  33.  
  34. ll output = combination(n, r);
  35. cout << output << endl;
  36. }
  37.  
  38. int main()
  39. {
  40. ios_base::sync_with_stdio(0);
  41. cin.tie(0);
  42.  
  43. ll t = 1;
  44. while (t--)
  45. {
  46. solve();
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5320KB
stdin
4 2
stdout
6