QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412092#4163. 地精部落x-camp0 0ms0kbC++171.1kb2024-05-16 04:41:342024-05-16 04:41:35

Judging History

你现在查看的是最新测评结果

  • [2024-05-16 04:41:35]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-16 04:41:34]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <fstream>
#include <cstring>

using namespace std;

int N, P;
#define NMAX 5000
long long dp[NMAX];
long long bi[NMAX][NMAX];

long long  binom (int n, int k, int p) {
    // Base Cases
    if (k > n)
        return 0;
    if (k == 0 || k == n)
        return 1;

    return (binom(n - 1, k - 1,p)
           + binom(n - 1, k,p)) %p;
}
int main() {
    freopen("goblin.in","r",stdin);
    freopen("goblin.out","w",stdout);
    cin >> N >> P;
    for (int i=0; i<N; i++) {
        bi[i][0] = 1;
        bi[i][i] = 1;
    }
    for (int i=1; i<N; i++) {
        for (int j=1; j<=i; j++) {
            bi[i][j] = (bi[i-1][j-1] + bi[i-1][j]) %P;
        }
    }
    // up pattern first
    dp[2] = 1; dp[1] = 1; dp[0] = 1;
    for (int i=3; i<=N; i++) {
        for (int j=2; j<=i; j += 2 ) {
            long long tmp = dp[j-1]*bi[i-1][j-1] %P;
            tmp = tmp *  dp[i-j] %P;
            dp[i] = (dp[i] + tmp) % P;
        }
    }
    if (N == 1) cout << 1;
    else cout << 2*dp[N] %P;
    return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

9 2811

output:


result:


Test #2:

score: 0
Dangerous Syscalls

input:

10 12929

output:


result:


Test #3:

score: 0
Dangerous Syscalls

input:

17 21929121

output:


result:


Test #4:

score: 0
Dangerous Syscalls

input:

18 29121

output:


result:


Test #5:

score: 0
Dangerous Syscalls

input:

200 123849291

output:


result:


Test #6:

score: 0
Dangerous Syscalls

input:

500 182739417

output:


result:


Test #7:

score: 0
Dangerous Syscalls

input:

550 281321834

output:


result:


Test #8:

score: 0
Dangerous Syscalls

input:

2500 18239314

output:


result:


Test #9:

score: 0
Dangerous Syscalls

input:

4000 129394123

output:


result:


Test #10:

score: 0
Dangerous Syscalls

input:

4200 192340123

output:


result: