Problem p03222 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <int MOD> struct modint {
  long long val;
  constexpr modint(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr modint operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr modint operator+(const modint &r) const noexcept {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint &r) const noexcept {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint &r) const noexcept {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint &r) const noexcept {
    return modint(*this) /= r;
  }
  constexpr modint &operator+=(const modint &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr modint &operator-=(const modint &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr modint &operator*=(const modint &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr modint &operator/=(const modint &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const modint &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const modint &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os,
                                       const modint<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr modint<MOD> modpow(const modint<MOD> &a,
                                      long long n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};
using mint = modint<MOD>;

mint dp[10][10];

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  rep(i, 10) rep(j, 10) dp[i][j] = 0;
  dp[0][0] = 1;
  rep(i, h) rep(j, w) {
    rep(k, 1 << (w - 1)) {
      bool ok = true;
      rep(l, w - 2) {
        if ((k & (1 << l)) && (k & (1 << (l + 1))))
          ok = false;
      }
      if (ok) {
        if (j > 0 && (k & 1 << (j - 1)))
          dp[i + 1][j] += dp[i][j - 1];
        else if (j < w - 1 && (k & 1 << j))
          dp[i + 1][j] += dp[i][j + 1];
        else
          dp[i + 1][j] += dp[i][j];
      }
    }
  }

  // rep(i, h+1) {
  //     rep(j, w) printf("%9d ", dp[i][j]);
  //     cout << endl;
  // }
  cout << dp[h][k - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <int MOD> struct modint {
  long long val;
  constexpr modint(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr modint operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr modint operator+(const modint &r) const noexcept {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint &r) const noexcept {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint &r) const noexcept {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint &r) const noexcept {
    return modint(*this) /= r;
  }
  constexpr modint &operator+=(const modint &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr modint &operator-=(const modint &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr modint &operator*=(const modint &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr modint &operator/=(const modint &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const modint &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const modint &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os,
                                       const modint<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr modint<MOD> modpow(const modint<MOD> &a,
                                      long long n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};
using mint = modint<MOD>;

mint dp[110][10];

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  rep(i, 10) rep(j, 10) dp[i][j] = 0;
  dp[0][0] = 1;
  rep(i, h) rep(j, w) {
    rep(k, 1 << (w - 1)) {
      bool ok = true;
      rep(l, w - 2) {
        if ((k & (1 << l)) && (k & (1 << (l + 1))))
          ok = false;
      }
      if (ok) {
        if (j > 0 && (k & 1 << (j - 1)))
          dp[i + 1][j] += dp[i][j - 1];
        else if (j < w - 1 && (k & 1 << j))
          dp[i + 1][j] += dp[i][j + 1];
        else
          dp[i + 1][j] += dp[i][j];
      }
    }
  }

  // rep(i, h+1) {
  //     rep(j, w) printf("%9d ", dp[i][j]);
  //     cout << endl;
  // }
  cout << dp[h][k - 1] << endl;
}