Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- int n, m;
- int cells[100000];
- int widths[100000];
- int res[100000];
- int backup[100000];
- void dfs(vector<int>& p, int current) {
- if (current == m) {
- //check
- for (int i = 0; i < m; ++i) {
- if (res[i] == 0)
- return;
- }
- for (auto it = p.begin(); it != p.end(); ++it) {
- cout << (*it)+1;
- if (it + 1 != p.end())
- cout << ' ';
- }
- exit(0);
- }
- for (int i = 0; i < n - widths[current] + 1; ++i) {
- p.push_back(i);
- for (int j = 0; j < widths[current]; ++j) {
- backup[j] = cells[i + j];
- cells[i + j] = current + 1;
- --res[backup[j]-1];
- ++res[current];
- }
- dfs(p, current + 1);
- p.pop_back();
- //복구
- for (int j = 0; j < widths[current]; ++j) {
- cells[i + j] = backup[j];
- ++res[backup[j] - 1];
- --res[current];
- }
- }
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cin >> n >> m;
- for (int i = 0; i < m; ++i) {
- cin >> widths[i];
- }
- vector<int> p;
- dfs(p, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment