// O(n^4) f[1][0] = 1; for (int i = 2; i <= n; i++) { for (int j = 0; j <= n * n; j++) { f[i][j] = 0; for (int t = 1; t <= i; t++) { f[i][j] = (f[i][j] + f[i - 1][j - t + 1]) % mod; } } }
// O(n^5) int ans = 0; for (int i = 1; i <= n; i++) { int add = 0; int upi = (0 + i - 1) * i / 2; for (int x = 0; x <= upi; x++) { for (int y = 0; y < x; y++) { int tmp = min(i - 1, x - y - 1); int sd = (i - 1 + i - tmp) * tmp / 2; // printf("x=%d y=%d %d\n", x, y, sd); add = (add + 1ll * sd * f[i - 1][x] % mod * f[i - 1][y]) % mod; } } // cout << "i=" << i << " add=" << add << endl; ans = (1ll * i * ans + add) % mod; } cout << ans << endl;
for (int i = 1; i <= n; i++) { for (int j = 0; j <= n * n; j++) { // printf("%d%c", f[i][j], j == n * n ? '\n' : ' '); } }