Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <math.h>
- #include <vector>
- #include <algorithm>
- #include <cstdio>
- #include <set>
- #include <queue>
- #include <sstream>
- #include <deque>
- #include <memory.h>
- #include <cassert>
- #include <ctime>
- #include <cstring>
- #include <cstdlib>
- using namespace std;
- #define ll long long
- #pragma comment(linker, "/STACK:64000000")
- const int maxn = 200200;
- const int inf = 1000000007;
- const int mod = 1000000007;
- const int dx[4] = {1, -1, 0, 0};
- const int dy[4] = {0, 0, 1, -1};
- int n;
- int a[maxn], p[maxn];
- bool used[maxn];
- void check() {
- vector<vector<int> > b(n + 2, vector<int>());
- for (int i = 1; i <= 2 * n; i++) {
- b[a[i]].push_back(i);
- }
- int cnt = 0;
- for (int i = 1; i <= n + 1; i++) {
- cnt += b[i].size() == 2 && b[i][1] - b[i][0] == i;
- }
- assert(cnt == n);
- }
- bool rec(int cur, int frst) {
- if (cur == n) {
- if (n == 0) {
- cout << "\"\", ";
- return 1;
- }
- cout << "\"";
- for (int i = 1; i <= 2 * n; i++) {
- cout << a[i];
- if (i == 2 * n) cout << "\", ";
- else cout << " ";
- }
- check();
- return 1;
- }
- while (a[frst] != -1) frst++;
- for (int i = n + 1; i >= 1; i--) {
- if (!used[i] && frst + i <= 2 * n && a[frst + i] == -1) {
- used[i] = 1;
- a[frst] = a[frst + i] = i;
- if (rec(cur + 1, frst + 1)) return 1;
- a[frst] = a[frst + i] = -1;
- used[i] = 0;
- }
- }
- return 0;
- }
- void generateAnswers() {
- cout << "const string ans[] = {";
- for (n = 0; n <= 100; n++) {
- memset(used, 0, sizeof(used));
- memset(a, -1, sizeof(a));
- if (!rec(0, 1)) {
- cout << "\"-1\", " << endl;
- }
- }
- }
- int main() {
- freopen("sequence.in", "r", stdin);
- freopen("sequence.out", "w", stdout);
- ios_base::sync_with_stdio(0);
- generateAnswers();
- /*int n;
- cin >> n;
- cout << ans[n] << endl; */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment