Problem p03772 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define LL long long
#define DB double
#define MAXN 100
#define MOD 1000000007
#define Pr pair<int, int>
#define X first
#define Y second
#define INF 1000000000000000000
#define mem(x, v) memset(x, v, sizeof(x))

LL read() {
  LL x = 0, F = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      F = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * F;
}

int n, a[MAXN + 5], ans;
int dp[MAXN + 5][MAXN + 5][MAXN + 5];

int add(int a, int b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(int a, int b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(int a, int b) { return (1LL * a * b) % MOD; }
int upd(int &a, int b) { a = add(a, b); }

int main() {
  n = read();
  for (int i = 1; i <= 2 * n - 1; i++)
    a[i] = read();
  sort(a + 1, a + 2 * n);
  dp[n][1][0] = 1;
  for (int i = n - 1; i >= 1; i--) {
    int al = (a[i + 1] != a[i]), ar = (a[2 * n - i - 1] != a[2 * n - i]);
    for (int l = 0; l <= 2 * n - 1; l++)
      for (int r = 0; l + r <= 2 * n - 1; r++)
        if (dp[i + 1][l][r]) {
          for (int dl = 1; dl <= l + al; dl++)
            upd(dp[i][l + al - dl + 1][r + ar + (dl > 1)],
                dp[i + 1][l][r]); // 将不走的情况合并在里面
          for (int dr = 1; dr <= r + ar; dr++)
            upd(dp[i][l + al + 1][r + ar - dr], dp[i + 1][l][r]);
        }
  }
  for (int l = 0; l <= 2 * n - 1; l++)
    for (int r = 0; l + r <= 2 * n - 1; r++)
      ans = add(ans, dp[1][l][r]);
  printf("%d\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define LL long long
#define DB double
#define MAXN 100
#define MOD 1000000007
#define Pr pair<int, int>
#define X first
#define Y second
#define INF 1000000000000000000
#define mem(x, v) memset(x, v, sizeof(x))

LL read() {
  LL x = 0, F = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      F = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * F;
}

int n, a[MAXN + 5], ans;
int dp[MAXN + 5][MAXN + 5][MAXN + 5];

int add(int a, int b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(int a, int b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(int a, int b) { return (1LL * a * b) % MOD; }
void upd(int &a, int b) { a = add(a, b); }

int main() {
  n = read();
  for (int i = 1; i <= 2 * n - 1; i++)
    a[i] = read();
  sort(a + 1, a + 2 * n);
  dp[n][1][0] = 1;
  for (int i = n - 1; i >= 1; i--) {
    int al = (a[i + 1] != a[i]), ar = (a[2 * n - i - 1] != a[2 * n - i]);
    for (int l = 0; l <= 2 * n - 1; l++)
      for (int r = 0; l + r <= 2 * n - 1; r++)
        if (dp[i + 1][l][r]) {
          for (int dl = 1; dl <= l + al; dl++)
            upd(dp[i][l + al - dl + 1][r + ar + (dl > 1)],
                dp[i + 1][l][r]); // 将不走的情况合并在里面
          for (int dr = 1; dr <= r + ar; dr++)
            upd(dp[i][l + al + 1][r + ar - dr], dp[i + 1][l][r]);
        }
  }
  for (int l = 0; l <= 2 * n - 1; l++)
    for (int r = 0; l + r <= 2 * n - 1; r++)
      ans = add(ans, dp[1][l][r]);
  printf("%d\n", ans);
}