Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int dp[20][1000];
void Init() {
  for (int i = 0; i <= 10; i++)
    for (int j = 0; j < 1000; j++)
      dp[i][j] = 0;

  for (int i = 0; i <= 9; i++) {
    dp[0][i]++;
    for (int j = 0; j <= 9; j++) {
      if (i == j)
        continue;
      dp[1][i + j * 2]++;
      for (int k = 0; k <= 9; k++) {
        if (k == i || k == j)
          continue;
        dp[2][i + j * 2 + k * 3]++;
        for (int l = 0; l <= 9; l++) {
          if (l == i || l == j || l == k)
            continue;
          dp[3][i + j * 2 + k * 3 + l * 4]++;
          for (int m = 0; m <= 9; m++) {
            if (m == i || m == j || m == k || m == l)
              continue;
            dp[4][i + j * 2 + k * 3 + l * 4 + m * 5]++;
            for (int n = 0; n <= 9; n++) {
              if (n == i || n == j || n == k || n == l || n == m)
                continue;
              dp[5][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6]++;
              for (int o = 0; o <= 9; o++) {
                if (o == i || o == j || o == k || o == l || o == m || o == n)
                  continue;
                dp[6][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7]++;
                for (int p = 0; p <= 9; p++) {
                  if (p == i || p == j || p == k || p == l || p == m ||
                      p == n || p == o)
                    continue;
                  dp[7][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7 +
                        p * 8]++;
                  for (int q = 0; q <= 9; q++) {
                    if (q == i || q == j || q == k || q == l || q == m ||
                        q == n || q == o || q == p)
                      continue;
                    dp[8][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7 +
                          p * 8 + q * 9]++;
                    for (int r = 0; r <= 9; r++) {
                      if (r == i || r == j || r == k || r == l || r == m ||
                          r == n || r == o || r == p || r == q)
                        continue;
                      dp[9][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7 +
                            p * 8 + q * 9 + r * 10]++;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  // cout << maxx << endl;
}

int main() {
  int n, s;
  Init();
  while (cin >> n >> s) {
    if (n == 0) {
      if (s == 0)
        cout << "1" << endl;
      else
        cout << "0" << endl;
    } else
      cout << dp[n - 1][s] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;
int cal[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int dp[9][50000000];
void Init() {

  for (int i = 0; i < 9; i++)
    for (int j = 0; j < 300; j++)
      dp[i][j] = 0;
  for (int i = 0; i <= 9; i++) {
    dp[0][i]++;
    for (int j = 0; j <= 9; j++) {
      if (i == j)
        continue;
      dp[1][i + j * 2]++;
      for (int k = 0; k <= 9; k++) {
        if (k == i || k == j)
          continue;
        dp[2][i + j * 2 + k * 3]++;
        for (int l = 0; l <= 9; l++) {
          if (l == i || l == j || l == k)
            continue;
          dp[3][i + j * 2 + k * 3 + l * 4]++;
          for (int m = 0; m <= 9; m++) {
            if (m == i || m == j || m == k || m == l)
              continue;
            dp[4][i + j * 2 + k * 3 + l * 4 + m * 5]++;
            for (int n = 0; n <= 9; n++) {
              if (n == i || n == j || n == k || n == l || n == m)
                continue;
              dp[5][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6]++;
              for (int o = 0; o <= 9; o++) {
                if (o == i || o == j || o == k || o == l || o == m || o == n)
                  continue;
                dp[6][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7]++;
                for (int p = 0; p <= 9; p++) {
                  if (p == i || p == j || p == k || p == l || p == m ||
                      p == n || p == o)
                    continue;
                  dp[7][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7 +
                        p * 8]++;
                  for (int q = 0; q <= 9; q++) {
                    if (q == i || q == j || q == k || q == l || q == m ||
                        q == n || q == o || q == p)
                      continue;
                    dp[8][i + j * 2 + k * 3 + l * 4 + m * 5 + n * 6 + o * 7 +
                          p * 8 + q * 9]++;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

int main() {
  int n, s, cnt, sum, div;
  Init();
  while (cin >> n >> s) {
    cout << dp[n - 1][s] << endl;
  }
  return 0;
}