Problem p00856 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#define MAX_N 100
#define MAX_T 100
using namespace std;

double mbg(int N, int T, int L, int B, int Lose[], int Back[]) {
  int t;
  double p_goal = 0;
  double ways[MAX_T + 1][MAX_N] = {{0}};

  t = 0;
  ways[0][0] = 1.0;
  while (t < T) {
    for (int i = 0; i < N; ++i) {
      for (int j = 1; j <= 6; ++j) {
        if ((i + j) <= N) {
          for (int k = 0; k < L; ++k) {
            if ((i + j) == Lose[k]) {
              ways[t + 2][i + j] += ways[t][i] / 6;
              goto escape1;
            }
          }
          for (int k = 0; k < B; ++k) {
            if ((i + j) == Back[k]) {
              ways[t + 1][0] += ways[t][i] / 6;
              goto escape1;
            }
          }
          ways[t + 1][i + j] += ways[t][i] / 6;
        escape1:;
        } else {
          for (int k = 0; k < L; ++k) {
            if ((2 * N - (i + j)) == Lose[k]) {
              ways[t + 2][2 * N - (i + j)] += ways[t][i] / 6;
              goto escape2;
            }
          }
          for (int k = 0; k < B; ++k) {
            if ((2 * N - (i + j)) == Back[k]) {
              ways[t + 1][0] += ways[t][i] / 6;
              goto escape2;
            }
          }
          ways[t + 1][2 * N - (i + j)] += ways[t][i] / 6;
        escape2:;
        }
      }
    }
    t++;
  }

  for (int i = 1; i <= T; ++i) {
    p_goal += ways[i][N];
  }
  return p_goal;
}

int main() {
  int N, T, L, B;
  while (1) {
    int *Lose, *Back;
    Lose = new int[MAX_N];
    Back = new int[MAX_N];
    cin >> N >> T >> L >> B;
    if (N == 0 && T == 0 && L == 0 && B == 0)
      break;
    for (int i = 0; i < L; ++i)
      cin >> Lose[i];
    for (int i = 0; i < B; ++i)
      cin >> Back[i];
    printf("%.6f\n", mbg(N, T, L, B, Lose, Back));
    delete[] Lose;
    delete[] Back;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#define MAX_N 100
#define MAX_T 100
using namespace std;

double mbg(int N, int T, int L, int B, int Lose[], int Back[]) {
  int t;
  double p_goal = 0;
  double ways[MAX_T + 2][MAX_N + 1] = {{0}};

  t = 0;
  ways[0][0] = 1.0;
  while (t < T) {
    for (int i = 0; i < N; ++i) {
      for (int j = 1; j <= 6; ++j) {
        if ((i + j) <= N) {
          for (int k = 0; k < L; ++k) {
            if ((i + j) == Lose[k]) {
              ways[t + 2][i + j] += ways[t][i] / 6;
              goto escape1;
            }
          }
          for (int k = 0; k < B; ++k) {
            if ((i + j) == Back[k]) {
              ways[t + 1][0] += ways[t][i] / 6;
              goto escape1;
            }
          }
          ways[t + 1][i + j] += ways[t][i] / 6;
        escape1:;
        } else {
          for (int k = 0; k < L; ++k) {
            if ((2 * N - (i + j)) == Lose[k]) {
              ways[t + 2][2 * N - (i + j)] += ways[t][i] / 6;
              goto escape2;
            }
          }
          for (int k = 0; k < B; ++k) {
            if ((2 * N - (i + j)) == Back[k]) {
              ways[t + 1][0] += ways[t][i] / 6;
              goto escape2;
            }
          }
          ways[t + 1][2 * N - (i + j)] += ways[t][i] / 6;
        escape2:;
        }
      }
    }
    t++;
  }

  for (int i = 1; i <= T; ++i) {
    p_goal += ways[i][N];
  }
  return p_goal;
}

int main() {
  int N, T, L, B;
  while (1) {
    int *Lose, *Back;
    Lose = new int[MAX_N];
    Back = new int[MAX_N];
    cin >> N >> T >> L >> B;
    if (N == 0 && T == 0 && L == 0 && B == 0)
      break;
    for (int i = 0; i < L; ++i)
      cin >> Lose[i];
    for (int i = 0; i < B; ++i)
      cin >> Back[i];
    printf("%.6f\n", mbg(N, T, L, B, Lose, Back));
    delete[] Lose;
    delete[] Back;
  }
  return 0;
}