답안 #770133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770133 2023-06-30T19:41:08 Z Ahmed57 Tents (JOI18_tents) C++17
100 / 100
349 ms 141712 KB
#include <bits/stdc++.h>

using namespace std;
long long nCr(long long x){
    return x*(x-1)/2;
}
long long n,m;
long long dp2[3001][3001],dp[3001][3001];
long long mod = 1000000007;
long long solve2(int i,int j){
    if(i==0){
        return 1;
    }
    if(dp2[i][j]!=-1)return dp2[i][j];
    long long c1 = solve2(i-1,j);
    if(j>=1)c1+=(solve2(i-1,j-1)*4ll*j)%mod;
    c1%=mod;
    if(j>=2)c1+=(solve2(i-1,j-2)*nCr(j))%mod;
    c1%=mod;
    return dp2[i][j] = c1;
}
long long solve(int i,int j){
    if(i==n){
        int rem = n-((m-j)/2);
        return solve2(j,rem);
        //base caseeee
    }
    if(dp[i][j]!=-1)return dp[i][j];
    long long c1 = solve(i+1,j);
    if(j>=2){
        c1+=(solve(i+1,j-2)*nCr(j))%mod;
    }c1%=mod;
    return dp[i][j] = c1;
}
int main(){
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    memset(dp2,-1,sizeof dp2);
    cout<<((solve(0,m)-1)%mod+mod)%mod;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 141208 KB Output is correct
2 Correct 48 ms 141200 KB Output is correct
3 Correct 47 ms 141188 KB Output is correct
4 Correct 47 ms 141284 KB Output is correct
5 Correct 50 ms 141220 KB Output is correct
6 Correct 49 ms 141288 KB Output is correct
7 Correct 48 ms 141204 KB Output is correct
8 Correct 52 ms 141268 KB Output is correct
9 Correct 49 ms 141264 KB Output is correct
10 Correct 50 ms 141192 KB Output is correct
11 Correct 49 ms 141272 KB Output is correct
12 Correct 51 ms 141256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 141208 KB Output is correct
2 Correct 48 ms 141200 KB Output is correct
3 Correct 47 ms 141188 KB Output is correct
4 Correct 47 ms 141284 KB Output is correct
5 Correct 50 ms 141220 KB Output is correct
6 Correct 49 ms 141288 KB Output is correct
7 Correct 48 ms 141204 KB Output is correct
8 Correct 52 ms 141268 KB Output is correct
9 Correct 49 ms 141264 KB Output is correct
10 Correct 50 ms 141192 KB Output is correct
11 Correct 49 ms 141272 KB Output is correct
12 Correct 51 ms 141256 KB Output is correct
13 Correct 48 ms 141316 KB Output is correct
14 Correct 53 ms 141360 KB Output is correct
15 Correct 208 ms 141600 KB Output is correct
16 Correct 61 ms 141392 KB Output is correct
17 Correct 78 ms 141456 KB Output is correct
18 Correct 86 ms 141444 KB Output is correct
19 Correct 246 ms 141708 KB Output is correct
20 Correct 199 ms 141516 KB Output is correct
21 Correct 144 ms 141480 KB Output is correct
22 Correct 127 ms 141528 KB Output is correct
23 Correct 72 ms 141440 KB Output is correct
24 Correct 349 ms 141712 KB Output is correct
25 Correct 266 ms 141636 KB Output is correct
26 Correct 301 ms 141660 KB Output is correct
27 Correct 323 ms 141680 KB Output is correct