Submission #44654

# Submission time Handle Problem Language Result Execution time Memory
44654 2018-04-04T10:51:16 Z PowerOfNinjaGo Tents (JOI18_tents) C++17
100 / 100
511 ms 36224 KB
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9+7;
const int maxn = 3e3+5;
int dp[maxn][maxn];
void add(int &a, int b)
{
    a += b;
    if(a>= md) a-= md;
}
int mul(int a, int b)
{
    return (1LL*a*b)%md;
}
int solve(int n, int m)
{
    if(n == 0 || m == 0) return 1;
    if(dp[n][m] != -1) return dp[n][m];
    int &res = dp[n][m];
    res = 0;
    add(res, mul(4*m, solve(n-1, m-1)));
    if(n>= 2) add(res, mul(m*(n-1), solve(n-2, m-1)));
    if(m>= 2) add(res, mul(m*(m-1)/2, solve(n-1, m-2)));
    add(res, solve(n-1, m));
    return res;
}
int main()
{
    int n, m; cin >> n >> m;
    memset(dp, -1, sizeof dp);
    cout << solve(n, m)-1 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 35576 KB Output is correct
2 Correct 26 ms 35812 KB Output is correct
3 Correct 27 ms 35812 KB Output is correct
4 Correct 28 ms 35860 KB Output is correct
5 Correct 28 ms 35860 KB Output is correct
6 Correct 28 ms 35888 KB Output is correct
7 Correct 27 ms 35912 KB Output is correct
8 Correct 27 ms 35932 KB Output is correct
9 Correct 26 ms 35932 KB Output is correct
10 Correct 28 ms 35932 KB Output is correct
11 Correct 27 ms 35932 KB Output is correct
12 Correct 31 ms 35964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 35576 KB Output is correct
2 Correct 26 ms 35812 KB Output is correct
3 Correct 27 ms 35812 KB Output is correct
4 Correct 28 ms 35860 KB Output is correct
5 Correct 28 ms 35860 KB Output is correct
6 Correct 28 ms 35888 KB Output is correct
7 Correct 27 ms 35912 KB Output is correct
8 Correct 27 ms 35932 KB Output is correct
9 Correct 26 ms 35932 KB Output is correct
10 Correct 28 ms 35932 KB Output is correct
11 Correct 27 ms 35932 KB Output is correct
12 Correct 31 ms 35964 KB Output is correct
13 Correct 27 ms 35964 KB Output is correct
14 Correct 28 ms 36092 KB Output is correct
15 Correct 294 ms 36184 KB Output is correct
16 Correct 29 ms 36184 KB Output is correct
17 Correct 49 ms 36184 KB Output is correct
18 Correct 80 ms 36184 KB Output is correct
19 Correct 324 ms 36184 KB Output is correct
20 Correct 318 ms 36184 KB Output is correct
21 Correct 155 ms 36184 KB Output is correct
22 Correct 182 ms 36184 KB Output is correct
23 Correct 140 ms 36184 KB Output is correct
24 Correct 511 ms 36184 KB Output is correct
25 Correct 340 ms 36224 KB Output is correct
26 Correct 407 ms 36224 KB Output is correct
27 Correct 421 ms 36224 KB Output is correct