QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252409 | #7712. Rikka with Bridges | SolitaryDream# | AC ✓ | 771ms | 8040kb | C++17 | 2.1kb | 2023-11-15 19:19:12 | 2023-11-15 19:19:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+1e2+7;
int T,n,K,P;
int f[N][9],dp[N][9],C[N][N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
f[1][0]=1; f[1][1]=0; f[1][2]=0; f[1][3]=0; f[1][4]=0; f[1][5]=0; f[1][6]=0; f[1][7]=0; f[1][8]=0;
f[2][0]=1; f[2][1]=0; f[2][2]=0; f[2][3]=0; f[2][4]=0; f[2][5]=0; f[2][6]=0; f[2][7]=0; f[2][8]=0;
f[3][0]=1; f[3][1]=3; f[3][2]=0; f[3][3]=0; f[3][4]=0; f[3][5]=0; f[3][6]=0; f[3][7]=0; f[3][8]=0;
f[4][0]=1; f[4][1]=0; f[4][2]=30; f[4][3]=4; f[4][4]=3; f[4][5]=0; f[4][6]=0; f[4][7]=0; f[4][8]=0;
f[5][0]=1; f[5][1]=0; f[5][2]=0; f[5][3]=150; f[5][4]=225; f[5][5]=162; f[5][6]=150; f[5][7]=30; f[5][8]=0;
f[6][0]=1; f[6][1]=0; f[6][2]=0; f[6][3]=0; f[6][4]=975; f[6][5]=1980; f[6][6]=2370; f[6][7]=3780; f[6][8]=5490;
f[7][0]=1; f[7][1]=0; f[7][2]=0; f[7][3]=0; f[7][4]=0; f[7][5]=7203; f[7][6]=26460; f[7][7]=28290; f[7][8]=58275;
f[8][0]=1; f[8][1]=0; f[8][2]=0; f[8][3]=0; f[8][4]=0; f[8][5]=0; f[8][6]=58940; f[8][7]=338520; f[8][8]=528360;
f[9][0]=1; f[9][1]=0; f[9][2]=0; f[9][3]=0; f[9][4]=0; f[9][5]=0; f[9][6]=0; f[9][7]=534348; f[9][8]=4492152;
f[10][0]=1; f[10][1]=0; f[10][2]=0; f[10][3]=0; f[10][4]=0; f[10][5]=0; f[10][6]=0; f[10][7]=0; f[10][8]=5353965;
cin>>T;
while(T--)
{
cin>>n>>K>>P;
// n=1000,K=8;
// P=rand()%100000+1;
for(int i=1;i<=n;i++)
f[i][0]=1;
C[0][0]=1;
for(int i=1;i<=n;i++)
{
C[i][0]=1;
for(int j=1;j<=i;j++)
C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
}
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
memset(dp[i],0,sizeof(dp[i]));
for(int j=1;j<=i;j++)
for(int p=0;p<=K;p++)
if(f[j][p])
for(int t=p;t<=K;t++)
dp[i][t]=(dp[i][t]+1ll*dp[i-j][t-p]*C[i-1][j-1]%P*f[j][p])%P;
}
int ans=0;
for(int i=0;i<=K;i++)
ans=(ans+dp[n][i])%P;
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 28ms
memory: 8020kb
input:
3 4 1 1000000007 4 2 1000000007 1000 8 1000000007
output:
27 57 509805471
result:
ok 3 number(s): "27 57 509805471"
Test #2:
score: 0
Accepted
time: 771ms
memory: 8040kb
input:
1000 947 1 190045441 921 0 190957342 925 3 379055266 922 3 138932561 965 8 952228308 919 7 140290004 970 4 995697796 902 6 576851770 927 8 144664381 931 7 208740840 943 6 371258405 928 1 214885391 960 2 394217446 954 5 653450475 904 7 203193504 979 0 112018196 923 4 664143610 993 2 725404445 923 3 7...
output:
61807195 188034611 43610239 134056614 710456426 78761784 876107835 85363001 46431730 142635522 241796906 64783608 168537413 326508850 57592149 35340001 312280924 351639512 83473039 363633444 625324787 181152844 751514576 404230266 93887237 138771641 564862182 225822133 284667554 580218579 125420274 ...
result:
ok 1000 numbers