QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#412088 | #4163. 地精部落 | x-camp | 0 | 0ms | 0kb | C++17 | 884b | 2024-05-16 04:25:24 | 2024-05-16 04:25:24 |
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;
int N, P;
#define NMAX 5000
long long dp[NMAX];
bool visited[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",stdin);
cin >> N >> 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]*binom(i-1,j-1,P) %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