Problem p02683 (C++)

Buggy submission (status: Runtime Error):
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

int32_t N, M, X;

int32_t book_cost[12];
int32_t A[12][12];

int32_t minimum_cost;
int32_t look_up[1 << 11];

int32_t Decode(const int32_t tried_book, vector<bool> book_studied) {
  book_studied[tried_book] = true;
  int32_t decoded = 0;
  for (int32_t i = 0; i < N; ++i) {
    decoded += (book_studied[i] ? 1 : 0);
    decoded *= 2;
  }
  return decoded;
}

void Dfs(const int32_t target_book, const int32_t cost_so_far,
         vector<int32_t> rikaido, vector<bool> book_studied) {
  for (int32_t j = 0; j < M; ++j) {
    rikaido[j] += A[target_book][j];
  }
  book_studied[target_book] = true;
  bool done = true;
  for (const int32_t r : rikaido) {
    done = done && (r >= X);
  }
  const int32_t c_cost = cost_so_far + book_cost[target_book];
  if (done) {
    if (c_cost < minimum_cost) {
      minimum_cost = c_cost;
    }
    return;
  }

  for (int32_t i = 0; i < N; ++i) {
    if (!book_studied[i] && (c_cost + book_cost[i] < minimum_cost)) {
      int32_t decoded = Decode(i, book_studied);
      if (look_up[decoded] == 0) {
        look_up[decoded] = 1;
        Dfs(i, c_cost, rikaido, book_studied);
      }
    }
  }
}

int main() {
  minimum_cost = INT32_MAX;
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> N >> M >> X;

  for (int32_t i = 0; i < N; ++i) {
    cin >> book_cost[i];
    for (int32_t j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }

  vector<int32_t> rikaido(M, 0);
  vector<bool> book_studied(N, false);
  for (int32_t i = 0; i < N; ++i) {
    Dfs(i, 0, rikaido, book_studied);
  }
  if (minimum_cost != INT32_MAX) {
    cout << minimum_cost << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Fixed submission:
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

int32_t N, M, X;

int32_t book_cost[12];
int32_t A[12][12];

int32_t minimum_cost;
int32_t look_up[1 << 13];

int32_t Decode(const int32_t tried_book, vector<bool> book_studied) {
  book_studied[tried_book] = true;
  int32_t decoded = 0;
  for (int32_t i = 0; i < N; ++i) {
    decoded += (book_studied[i] ? 1 : 0);
    decoded *= 2;
  }
  return decoded;
}

void Dfs(const int32_t target_book, const int32_t cost_so_far,
         vector<int32_t> rikaido, vector<bool> book_studied) {
  for (int32_t j = 0; j < M; ++j) {
    rikaido[j] += A[target_book][j];
  }
  book_studied[target_book] = true;
  bool done = true;
  for (const int32_t r : rikaido) {
    done = done && (r >= X);
  }
  const int32_t c_cost = cost_so_far + book_cost[target_book];
  if (done) {
    if (c_cost < minimum_cost) {
      minimum_cost = c_cost;
    }
    return;
  }

  for (int32_t i = 0; i < N; ++i) {
    if (!book_studied[i] && (c_cost + book_cost[i] < minimum_cost)) {
      int32_t decoded = Decode(i, book_studied);
      if (look_up[decoded] == 0) {
        look_up[decoded] = 1;
        Dfs(i, c_cost, rikaido, book_studied);
      }
    }
  }
}

int main() {
  minimum_cost = INT32_MAX;
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> N >> M >> X;

  for (int32_t i = 0; i < N; ++i) {
    cin >> book_cost[i];
    for (int32_t j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }

  vector<int32_t> rikaido(M, 0);
  vector<bool> book_studied(N, false);
  for (int32_t i = 0; i < N; ++i) {
    Dfs(i, 0, rikaido, book_studied);
  }
  if (minimum_cost != INT32_MAX) {
    cout << minimum_cost << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}