fork(5) download
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #define INF UINT_MAX
  4.  
  5. long long unsigned fact(unsigned n)
  6. {
  7. return n ? n * fact(n-1) : 1;
  8. }
  9.  
  10. unsigned C(unsigned n, unsigned k)
  11. {
  12. return fact(n)/(fact(k) * fact(n-k));
  13. }
  14.  
  15. unsigned F(unsigned N, unsigned L, unsigned R)
  16. {
  17. unsigned pos, sum = 0;
  18. if(R != INF)
  19. {
  20. if(L == 0 || R == 0 || N < L || N < R) return 0;
  21. if(L == 1) return F(N-1, R-1, INF);
  22. if(R == 1) return F(N-1, L-1, INF);
  23. for(pos = L; pos <= N-R+1; ++pos)
  24. sum += C(N-1, pos-1) * F(pos-1, L-1, INF) * F(N-pos, R-1, INF);
  25. }
  26. else
  27. {
  28. if(L == 1) return fact(N-1);
  29. for(pos = L; pos <= N; ++pos)
  30. sum += C(N-1, pos-1) * F(pos-1, L-1, INF) * fact(N-pos);
  31. }
  32. return sum;
  33. }
  34.  
  35. int main()
  36. {
  37. printf("%u\n", F(10,4,3));
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
224490