Submission #333482

# Submission time Handle Problem Language Result Execution time Memory
333482 2020-12-06T08:32:48 Z benson1029 Tents (JOI18_tents) C++14
100 / 100
186 ms 71020 KB
#include<bits/stdc++.h>
#define MOD ((long long)1e9+7)
using namespace std;
int n,m;
long long dp[3005][3005];
int main() {
	cin >> n >> m;
	dp[0][0] = 1LL;
	for(int i=0; i<n; i++) {
		for(int j=0; j<=m; j++) {
			if(j+2<=m) {
				dp[i+1][j+2] += (((m-j)*(m-j-1LL)/2)%MOD) * dp[i][j];
				dp[i+1][j+2] %= MOD;
			}
			if(j<m) {
				dp[i+1][j+1] += dp[i][j] * (m-j) * 4LL;
				dp[i+1][j+1] %= MOD;
			}
			if(i<n-1) {
				dp[i+2][j+1] += dp[i][j] * ((((long long)m-j)*(i+1))%MOD);
				dp[i+2][j+1] %= MOD;
			}
		}
		for(int j=0; j<=m; j++) {
			dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= MOD;
		}
	}
	long long ans = 0;
	for(int j=1; j<=m; j++) {
		ans += dp[n][j];
	}
	cout << ans%MOD << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 2 ms 1388 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 2 ms 1516 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 2 ms 1388 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 2 ms 1516 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 2284 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 7 ms 9964 KB Output is correct
15 Correct 119 ms 55148 KB Output is correct
16 Correct 9 ms 4076 KB Output is correct
17 Correct 28 ms 12908 KB Output is correct
18 Correct 42 ms 17152 KB Output is correct
19 Correct 140 ms 62956 KB Output is correct
20 Correct 113 ms 50924 KB Output is correct
21 Correct 84 ms 33824 KB Output is correct
22 Correct 74 ms 35516 KB Output is correct
23 Correct 47 ms 27116 KB Output is correct
24 Correct 181 ms 71020 KB Output is correct
25 Correct 157 ms 61292 KB Output is correct
26 Correct 155 ms 66668 KB Output is correct
27 Correct 186 ms 69100 KB Output is correct