fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int squares (int i) {
  5. if (i & 1)
  6. return i / 4 * 2 + 1;
  7. else
  8. return (i - 1) / 4 * 2 + 2;
  9. }
  10.  
  11. int bishop_placements(int N, int K)
  12. {
  13. if (K > 2 * N - 1)
  14. return 0;
  15.  
  16. vector<vector<int>> D(N * 2, vector<int>(K + 1));
  17. for (int i = 0; i < N * 2; ++i)
  18. D[i][0] = 1;
  19. D[1][1] = 1;
  20. for (int i = 2; i < N * 2; ++i)
  21. for (int j = 1; j <= K; ++j)
  22. D[i][j] = D[i-2][j] + D[i-2][j-1] * (squares(i) - j + 1);
  23.  
  24. int ans = 0;
  25. for (int i = 0; i <= K; ++i)
  26. ans += D[N*2-1][i] * D[N*2-2][K-i];
  27. return ans;
  28. }
  29.  
  30. int main() {
  31. // your code goes here
  32. cout << bishop_placements(3,2);
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
26