Submission #60066

# Submission time Handle Problem Language Result Execution time Memory
60066 2018-07-23T15:16:08 Z XmtosX Tents (JOI18_tents) C++17
100 / 100
425 ms 59308 KB
#include <bits/stdc++.h>
using namespace std;
long long dp1(long long x,long long rem);
const int N=3003,mod=1e9+7;
int n,m;
long long memo[N][N],memo1[N][N];
long long dp (long long x,long long rem)
{
    if (x==m)
    {
        return (rem!=n);
    }
    long long &ret= memo[x][rem];
    if (ret)
        return ret;
    ret= dp(x+1,rem);
    if (rem>=2)
    {
        ret+= dp(x+1,rem-2)*(rem*(rem-1)/2);
        ret%=mod;
    }
    if (rem>=1)
    {
        ret+= dp(x+1,rem-1)*rem*4;
        ret%=mod;
        if (x+2<=m)
        {
            ret+= (dp(x+2,rem-1)*rem*(m-x-1));
            ret%=mod;
        }
    }
    return ret;
}

int main()
{
    cin >>n>>m;
    cout <<dp(0,n);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 1256 KB Output is correct
3 Correct 2 ms 1256 KB Output is correct
4 Correct 3 ms 1256 KB Output is correct
5 Correct 6 ms 1600 KB Output is correct
6 Correct 3 ms 1600 KB Output is correct
7 Correct 5 ms 1600 KB Output is correct
8 Correct 3 ms 1600 KB Output is correct
9 Correct 3 ms 1600 KB Output is correct
10 Correct 3 ms 1600 KB Output is correct
11 Correct 4 ms 1772 KB Output is correct
12 Correct 7 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 1256 KB Output is correct
3 Correct 2 ms 1256 KB Output is correct
4 Correct 3 ms 1256 KB Output is correct
5 Correct 6 ms 1600 KB Output is correct
6 Correct 3 ms 1600 KB Output is correct
7 Correct 5 ms 1600 KB Output is correct
8 Correct 3 ms 1600 KB Output is correct
9 Correct 3 ms 1600 KB Output is correct
10 Correct 3 ms 1600 KB Output is correct
11 Correct 4 ms 1772 KB Output is correct
12 Correct 7 ms 2288 KB Output is correct
13 Correct 12 ms 8180 KB Output is correct
14 Correct 2 ms 8180 KB Output is correct
15 Correct 258 ms 36120 KB Output is correct
16 Correct 30 ms 36120 KB Output is correct
17 Correct 66 ms 36120 KB Output is correct
18 Correct 81 ms 36120 KB Output is correct
19 Correct 357 ms 41392 KB Output is correct
20 Correct 256 ms 41392 KB Output is correct
21 Correct 222 ms 41392 KB Output is correct
22 Correct 145 ms 41392 KB Output is correct
23 Correct 35 ms 41392 KB Output is correct
24 Correct 425 ms 59308 KB Output is correct
25 Correct 359 ms 59308 KB Output is correct
26 Correct 361 ms 59308 KB Output is correct
27 Correct 424 ms 59308 KB Output is correct