description: The Winter holiday will be here soon. Mr. Chanek wants to decorate his house's wall with ornaments. The wall can be represented as a binary string a of length n. His favorite nephew has another binary string b of length m (m ≤ n).
  
  Mr. Chanek's nephew loves the non-negative integer k. His nephew wants exactly k occurrences of b as substrings in a. 
  
  However, Mr. Chanek does not know the value of k. So, for each k (0 ≤ k ≤ n - m + 1), find the minimum number of elements in a that have to be changed such that there are exactly k occurrences of b in a.
  
  A string s occurs exactly k times in t if there are exactly k different pairs (p,q) such that we can obtain s by deleting p characters from the beginning and q characters from the end of t.
  
  Input
  
  The first line contains two integers n and m (1 ≤ m ≤ n ≤ 500) — size of the binary string a and b respectively.
  
  The second line contains a binary string a of length n.
  
  The third line contains a binary string b of length m.
  
  Output
  
  Output n - m + 2 integers — the (k+1)-th integer denotes the minimal number of elements in a that have to be changed so there are exactly k occurrences of b as a substring in a.
  
  Example
  
  Input
  
  
  9 3
  100101011
  101
  
  
  Output
  
  
  1 1 0 1 6 -1 -1 -1
  
  Note
  
  For k = 0, to make the string a have no occurrence of 101, you can do one character change as follows.
  
  100101011 → 100100011
  
  For k = 1, you can also change a single character.
  
  100101011 → 100001011
  
  For k = 2, no changes are needed.
solution: #include <bits/stdc++.h>
  template <class T>
  using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
  template <class T>
  using MaxHeap = std::priority_queue<T>;
  using ll = long long;
  using Pii = std::pair<int, int>;
  using Pll = std::pair<ll, ll>;
  using Pdd = std::pair<double, double>;
  template <class T>
  bool chmin(T &a, const T b) {
    if (a > b) {
      a = b;
      return true;
    } else {
      return false;
    }
  }
  template <class T>
  bool chmax(T &a, const T b) {
    if (a < b) {
      a = b;
      return true;
    } else {
      return false;
    }
  }
  template <class T>
  void vdeb(const std::vector<T> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
      if (i == n - 1)
        std::cout << da[i];
      else
        std::cout << da[i] << " ";
    }
    std::cout << std::endl;
  }
  template <class T>
  void vdeb(const std::vector<std::vector<T>> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
      std::cout << i << " : ";
      vdeb(da[i]);
    }
  }
  template <>
  void vdeb(const std::vector<std::string> &da) {
    auto n = da.size();
    for (size_t i = 0; i < n; i++) {
      std::cout << da[i] << std::endl;
    }
  }
  using namespace std;
  const int INF = 1 << 20;
  int main() {
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    vector<int> da(m + 1, 0);
    for (int i = (1); i < int(m); i++) {
      for (int j = (0); j < int(i); j++) {
        if (t[i] == t[j]) continue;
        bool flg = true;
        for (int k = (0); k < int(j); k++) {
          if (t[i - k - 1] != t[j - k - 1]) {
            flg = false;
            break;
          }
        }
        if (flg) chmax(da[i], j + 1);
      }
    }
    for (int i = (0); i < int(m - 1); i++) {
      bool flg = true;
      for (int j = (0); j < int(i + 1); j++) {
        if (t[m - j - 1] != t[i - j]) {
          flg = false;
          break;
        }
      }
      if (flg) chmax(da[m], i + 1);
    }
    vector<vector<int>> dp0(n + 1, vector<int>(m, INF));
    vector<vector<int>> dp1(n + 1, vector<int>(m, INF));
    dp0[0][0] = 0;
    for (int i = (0); i < int(n); i++) {
      for (int j = (0); j < int(m); j++) {
        if (s[i] == t[j]) {
          if (j == m - 1) {
            for (int k = (0); k < int(n); k++) {
              chmin(dp1[k + 1][da[j + 1]], dp0[k][j]);
              chmin(dp1[k][da[j]], dp0[k][j] + 1);
            }
          } else {
            for (int k = (0); k < int(n + 1); k++) {
              chmin(dp1[k][j + 1], dp0[k][j]);
              chmin(dp1[k][da[j]], dp0[k][j] + 1);
            }
          }
        } else {
          if (j == m - 1) {
            for (int k = (0); k < int(n); k++) {
              chmin(dp1[k + 1][da[j + 1]], dp0[k][j] + 1);
              chmin(dp1[k][da[j]], dp0[k][j]);
            }
          } else {
            for (int k = (0); k < int(n + 1); k++) {
              chmin(dp1[k][j + 1], dp0[k][j] + 1);
              chmin(dp1[k][da[j]], dp0[k][j]);
            }
          }
        }
        for (int k = (0); k < int(n + 1); k++) dp0[k][j] = INF;
      }
      swap(dp0, dp1);
    }
    vector<int> ans(n - m + 2, INF);
    for (int i = (0); i < int(n - m + 2); i++) {
      for (int j = (0); j < int(m); j++) chmin(ans[i], dp0[i][j]);
    }
    for (auto &i : ans)
      if (i == INF) i = -1;
    vdeb(ans);
  }
  