답안 #586108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586108 2022-06-29T22:34:45 Z GusterGoose27 Tents (JOI18_tents) C++11
100 / 100
111 ms 70704 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 3000;
const int MOD = 1e9+7;
ll dp[MAXN+1][MAXN+1];
ll n, m;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (ll i = 0; i <= n; i++) {
		for (ll j = 0; j <= m; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 1;
				continue;
			}
			ll m1 = j*(i-1);
			m1 %= MOD;
			ll m2 = j*(j-1)/2;
			m2 %= MOD;
			dp[i][j] += 4*j*dp[i-1][j-1];
			dp[i][j] %= MOD;
			dp[i][j] += dp[i-1][j];
			dp[i][j] %= MOD;
			if (j > 1) dp[i][j] += m2*dp[i-1][j-2];
			dp[i][j] %= MOD;
			if (i > 1) dp[i][j] += m1*dp[i-2][j-1];
			dp[i][j] %= MOD;
		}
	}
	cout << ((dp[n][m]-1+MOD)%MOD) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 1140 KB Output is correct
5 Correct 1 ms 708 KB Output is correct
6 Correct 2 ms 1364 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 1348 KB Output is correct
9 Correct 1 ms 708 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 1140 KB Output is correct
5 Correct 1 ms 708 KB Output is correct
6 Correct 2 ms 1364 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 1348 KB Output is correct
9 Correct 1 ms 708 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 2132 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 4 ms 9684 KB Output is correct
15 Correct 85 ms 55172 KB Output is correct
16 Correct 7 ms 3956 KB Output is correct
17 Correct 17 ms 12756 KB Output is correct
18 Correct 22 ms 16972 KB Output is correct
19 Correct 85 ms 62908 KB Output is correct
20 Correct 67 ms 50820 KB Output is correct
21 Correct 46 ms 33800 KB Output is correct
22 Correct 49 ms 35440 KB Output is correct
23 Correct 28 ms 26956 KB Output is correct
24 Correct 111 ms 70704 KB Output is correct
25 Correct 85 ms 61148 KB Output is correct
26 Correct 96 ms 66540 KB Output is correct
27 Correct 107 ms 68824 KB Output is correct