Problem p03222 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 100;
// ここまでテンプレ
int main() {
  ll H, W, K;
  cin >> H >> W >> K;
  // DP[i][j]=i本目の縦棒時点でjにたどりつくあみだくじの数
  ll DP[SIZE][SIZE] = {};
  DP[0][0] = 1;

  int X = W - 1;
  for (int i = 1; i <= H; i++) {
    for (int state = 0; state < (1 << X); state++) {
      // stateがvalidかどうか判定する
      bool valid = true;
      for (int j = 0; j < X; j++)
        if ((state & (1 << j)) && (state & (1 << (j + 1))))
          valid = false;
      if (!valid)
        continue;
      // cout<<bitset<10>(state)<<endl;
      // DPテーブルを更新する
      for (int j = 0; j < W; j++) {
        // 左に行く
        if (j != 0 && (state & (1 << (j - 1)))) {
          DP[i][j - 1] += DP[i - 1][j];
          DP[i][j - 1] %= MOD;
        }
        // 右に行く
        else if (j != W - 1 && (state & (1 << j))) {
          DP[i][j + 1] += DP[i - 1][j];
          DP[i][j + 1] %= MOD;
        }
        // そのまま
        else {
          DP[i][j] += DP[i - 1][j];
          DP[i][j] %= MOD;
        }
      }
    }
  }
  cout << DP[H][K - 1] << endl;
  /*
  for(int i=0;i<=H;i++){
          for(int j=0;j<W;j++){
                  cout<<DP[i][j]<<" ";
          }
          cout<<endl;
  }
  */
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 150;
// ここまでテンプレ
int main() {
  ll H, W, K;
  cin >> H >> W >> K;
  // DP[i][j]=i本目の縦棒時点でjにたどりつくあみだくじの数
  ll DP[SIZE][SIZE] = {};
  DP[0][0] = 1;

  int X = W - 1;
  for (int i = 1; i <= H; i++) {
    for (int state = 0; state < (1 << X); state++) {
      // stateがvalidかどうか判定する
      bool valid = true;
      for (int j = 0; j < X; j++)
        if ((state & (1 << j)) && (state & (1 << (j + 1))))
          valid = false;
      if (!valid)
        continue;
      // cout<<bitset<10>(state)<<endl;
      // DPテーブルを更新する
      for (int j = 0; j < W; j++) {
        // 左に行く
        if (j != 0 && (state & (1 << (j - 1)))) {
          DP[i][j - 1] += DP[i - 1][j];
          DP[i][j - 1] %= MOD;
        }
        // 右に行く
        else if (j != W - 1 && (state & (1 << j))) {
          DP[i][j + 1] += DP[i - 1][j];
          DP[i][j + 1] %= MOD;
        }
        // そのまま
        else {
          DP[i][j] += DP[i - 1][j];
          DP[i][j] %= MOD;
        }
      }
    }
  }
  cout << DP[H][K - 1] << endl;
  /*
  for(int i=0;i<=H;i++){
          for(int j=0;j<W;j++){
                  cout<<DP[i][j]<<" ";
          }
          cout<<endl;
  }
  */
  return 0;
}