QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782905#9561. 树数叔术FanyuX20 378ms16648kbC++141.1kb2024-11-25 22:05:442024-11-25 22:05:45

Judging History

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

  • [2024-11-25 22:05:45]
  • 评测
  • 测评结果:20
  • 用时:378ms
  • 内存:16648kb
  • [2024-11-25 22:05:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
const int inf=0x3f3f3f3f;
inline int rd(){
	int x=0,y=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')y=-1;
	for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return x*y;
}
const int N=150+5;
int n,m,mod,c[N][N],fac[N],f[N][N][N];
void add(int &x,int y){
    x+=y;if(x>=mod)x-=mod;
}
signed main(){
	n=rd();m=rd();mod=rd();
    if(m>=n)return puts("0"),0;
    fac[0]=c[0][0]=f[0][1][0]=1;
    for(int i=1;i<=n;i++){
        fac[i]=1ll*fac[i-1]*i%mod;
        c[i][0]=1;
        for(int j=1;j<=i;j++)
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
    }
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            for(int k=0;k<=j;k++){
                for(int l=0;l<k;l++)add(f[i][j][l],1ll*f[i-1][j][k]*c[k][l]%mod);
                for(int l=1;l<=n-j;l++)add(f[i][j+l][k+l-1],1ll*f[i-1][j][k]*j%mod);
            }
    cout<<f[m][n][0]*fac[n]%mod<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3636kb

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3696kb

input:

4 684813415 564954712

output:

0

result:

ok single line: '0'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3652kb

input:

4 2 844826878

output:

24

result:

ok single line: '24'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3708kb

input:

4 17724073 252218682

output:

0

result:

ok single line: '0'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3724kb

input:

4 3 697681963

output:

384

result:

ok single line: '384'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 0ms
memory: 3672kb

input:

6 4 956647977

output:

238320

result:

ok single line: '238320'

Test #7:

score: 15
Accepted
time: 0ms
memory: 3708kb

input:

6 450615260 491361886

output:

0

result:

ok single line: '0'

Test #8:

score: 15
Accepted
time: 0ms
memory: 3688kb

input:

6 5 339344353

output:

933120

result:

ok single line: '933120'

Test #9:

score: 15
Accepted
time: 0ms
memory: 3544kb

input:

6 3 842228619

output:

23760

result:

ok single line: '23760'

Test #10:

score: 15
Accepted
time: 0ms
memory: 3676kb

input:

6 5 331699652

output:

933120

result:

ok single line: '933120'

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 4ms
memory: 4400kb

input:

48 26 424594716

output:

299050116

result:

wrong answer 1st lines differ - expected: '362283012', found: '299050116'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 50
Accepted
time: 0ms
memory: 3560kb

input:

150 526250070 197316869

output:

0

result:

ok single line: '0'

Test #17:

score: 0
Wrong Answer
time: 378ms
memory: 16648kb

input:

149 116 671784452

output:

392295776

result:

wrong answer 1st lines differ - expected: '18945228', found: '392295776'