Guest User

is this right??

a guest
Apr 3rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int n, m;
  7. int cells[100000];
  8. int widths[100000];
  9. int res[100000];
  10. int backup[100000];
  11.  
  12. void dfs(vector<int>& p, int current) {
  13.     if (current == m) {
  14.         //check
  15.         for (int i = 0; i < m; ++i) {
  16.             if (res[i] == 0)
  17.                 return;
  18.         }
  19.  
  20.         for (auto it = p.begin(); it != p.end(); ++it) {
  21.             cout << (*it)+1;
  22.             if (it + 1 != p.end())
  23.                 cout << ' ';
  24.         }
  25.         exit(0);
  26.     }
  27.  
  28.  
  29.     for (int i = 0; i < n - widths[current] + 1; ++i) {
  30.         p.push_back(i);
  31.  
  32.         for (int j = 0; j < widths[current]; ++j) {
  33.             backup[j] = cells[i + j];
  34.             cells[i + j] = current + 1;
  35.  
  36.             --res[backup[j]-1];
  37.             ++res[current];
  38.         }
  39.  
  40.         dfs(p, current + 1);
  41.  
  42.         p.pop_back();
  43.  
  44.         //복구
  45.         for (int j = 0; j < widths[current]; ++j) {
  46.             cells[i + j] = backup[j];
  47.  
  48.             ++res[backup[j] - 1];
  49.             --res[current];
  50.         }
  51.     }
  52. }
  53.  
  54. int main()
  55. {
  56. #ifndef ONLINE_JUDGE
  57.     freopen("input.txt", "r", stdin);
  58. #endif
  59.     ios_base::sync_with_stdio(false);
  60.     cin.tie(NULL);
  61.  
  62.     cin >> n >> m;
  63.     for (int i = 0; i < m; ++i) {
  64.         cin >> widths[i];
  65.     }
  66.  
  67.  
  68.     vector<int> p;
  69.     dfs(p, 0);
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment