fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int res = 0;
  5.  
  6. void bt(int n, int pos, int open, int val){
  7. if(pos == 2 * n) {
  8. if(val == 0) res++;
  9. return;
  10. } if(val - 1 >= 0) bt(n, pos + 1, open, val - 1);
  11. if(open < n) bt(n, pos + 1, open + 1, val + 1);
  12. }
  13.  
  14. void solve(){
  15. int n; cin >> n;
  16. bt(n, 1, 1, 1);
  17. cout << res << "\n";
  18. }
  19.  
  20. int main(){
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(NULL); cout.tie(NULL);
  23. solve();
  24. }
Success #stdin #stdout 0.01s 5296KB
stdin
2
stdout
2