fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int comb[31][31];
  5. int compute(int M, int N);
  6. int main()
  7. {
  8. comb[0][0] = 1;
  9. for (int i = 0; i < 31; i++){
  10. comb[i][0] = 1;
  11. comb[i][1] = i;
  12. for (int j = 1; j < 31; j++) {
  13. comb[i][j] = -1;
  14. }
  15. }
  16. int T, M, N;
  17. vector<int> output;
  18. cin >> T;
  19. for (int i = 0; i < T; i++) {
  20. cin >> N >> M;
  21. output.push_back(compute(M, N));
  22. }
  23. vector<int>::iterator iter = output.begin();
  24. vector<int>::iterator end = output.end();
  25. while (iter != end) {
  26. cout << *iter << endl;
  27. iter++;
  28. }
  29.  
  30.  
  31. return 0;
  32. }
  33. int compute(int M, int N) {
  34. if (comb[M][N] != -1) { return comb[M][N]; }
  35. comb[M][N] = compute(M - 1, N)+ compute(M - 1, N - 1);
  36. return comb[M][N];
  37. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
2 2
1 5
13 29
stdout
1
5
-655727469