Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <cmath>
- using namespace std;
- bool isWay (vector < pair < int, int > > &points, int n) {
- bool is_way = true;
- for (int f = 0; f < n - 1; f++) {
- int x0 = points[f].first;
- int y0 = points[f].second;
- for (int s = f + 1; s < n; s++) {
- int x1 = points[s].first;
- int y1 = points[s].second;
- if (x0 == x1 || y0 == y1 || abs(x0 - x1) == abs(y0 - y1)) {
- is_way = false;
- break;
- }
- }
- if (!is_way) {
- break;
- }
- }
- return is_way;
- }
- int getNumberOfCombinationsByPos (int &n, int x, int y, vector < pair < int, int > > &points) {
- int combinations = 0;
- points[x] = {x, y};
- if (!isWay(points, x + 1) || x == n - 1) {
- if (isWay(points, x + 1)) {
- combinations = combinations + 1;
- }
- return combinations;
- }
- for (int t = y - 2; t >= 0; t--) {
- combinations += getNumberOfCombinationsByPos (n, x + 1, t, points);
- }
- for (int t = y + 2; t < n; t++) {
- combinations += getNumberOfCombinationsByPos (n, x + 1, t, points);
- }
- return combinations;
- }
- int main() {
- int n, combinations = 0;
- cin >> n;
- vector < pair < int, int > > points(n);
- for (int j = 0; j < n; j++) {
- combinations += getNumberOfCombinationsByPos (n, 0, j,points);
- }
- cout << combinations << endl;
- // cout << (double)clock() / CLOCKS_PER_SEC << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement