QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#251501#7774. 基础寄术练习题zhouhuanyi85 325ms189916kbC++141.4kb2023-11-14 19:41:382023-11-14 19:41:38

Judging History

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

  • [2023-11-14 19:41:38]
  • 评测
  • 测评结果:85
  • 用时:325ms
  • 内存:189916kb
  • [2023-11-14 19:41:38]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 100
#define M 10000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int n,m,k,mod,ans,inv[M+1],dp[N+1][N+1],DP[N+1][N+1][M+1][2];
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int main()
{
	n=read(),m=read(),k=read(),mod=read(),inv[1]=1;
	for (int i=2;i<=M;++i) inv[i]=MD2(-1ll*(mod/i)*inv[mod%i]%mod);
	if (k==1)
	{
		for (int i=0;i<=m;++i) dp[0][i]=1;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				dp[i][j]=MD(dp[i][j-1]+1ll*dp[i-1][j-1]*inv[j]%mod);
		printf("%d\n",dp[n][m]);
	}
	else
	{
		for (int i=0;i<=m;++i) DP[0][i][0][0]=MD2(-1);
		for (int i=1;i<=n;++i)
			for (int j=1;j<=m;++j)
				for (int k=0;k<=n*m;++k)
				{
					for (int op=0;op<=1;++op) Adder(DP[i][j][k][op],DP[i][j-1][k][op]),Adder(DP[i][j][k][op],1ll*DP[i-1][j-1][k][op]*inv[j]%mod);
					if (k>=j)
					{
						Adder2(DP[i][j][k][1],-1ll*DP[i-1][j-1][k-j][0]*j%mod);
						for (int op=0;op<=1;++op) Adder2(DP[i][j][k][op],-1ll*DP[i-1][j-1][k-j][op]*inv[j]%mod);
					}
				}
		for (int i=1;i<=n*m;++i) Adder(ans,1ll*DP[n][m][i][1]*inv[i]%mod);
		printf("%d\n",ans);
	}
	return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3796kb

input:

9 16 1 327134593

output:

162102742

result:

ok single line: '162102742'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

11 18 1 834359503

output:

256188485

result:

ok single line: '256188485'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

18 18 1 614802701

output:

552168146

result:

ok single line: '552168146'

Test #4:

score: 0
Accepted
time: 0ms
memory: 6564kb

input:

7 16 2 861918403

output:

306693876

result:

ok single line: '306693876'

Test #5:

score: 0
Accepted
time: 2ms
memory: 6920kb

input:

11 17 2 617904383

output:

393900291

result:

ok single line: '393900291'

Subtask #2:

score: 25
Accepted

Test #6:

score: 25
Accepted
time: 0ms
memory: 3948kb

input:

60 98 1 715015339

output:

690737273

result:

ok single line: '690737273'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

96 97 1 507892589

output:

481151247

result:

ok single line: '481151247'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

90 95 1 621080027

output:

255353202

result:

ok single line: '255353202'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

85 94 1 297115421

output:

122254364

result:

ok single line: '122254364'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

81 91 1 460412027

output:

148037986

result:

ok single line: '148037986'

Subtask #3:

score: 15
Accepted

Test #11:

score: 15
Accepted
time: 16ms
memory: 14768kb

input:

29 29 2 545875273

output:

171843225

result:

ok single line: '171843225'

Test #12:

score: 0
Accepted
time: 12ms
memory: 14776kb

input:

29 29 2 342070607

output:

291380196

result:

ok single line: '291380196'

Test #13:

score: 0
Accepted
time: 17ms
memory: 15928kb

input:

30 30 2 293965439

output:

148471965

result:

ok single line: '148471965'

Test #14:

score: 0
Accepted
time: 14ms
memory: 16048kb

input:

30 30 2 528219961

output:

203632962

result:

ok single line: '203632962'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

30 30 1 202836509

output:

158493990

result:

ok single line: '158493990'

Subtask #4:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 11ms
memory: 14304kb

input:

27 30 2 360712453

output:

80987914

result:

ok single line: '80987914'

Test #17:

score: 0
Accepted
time: 13ms
memory: 13396kb

input:

26 29 2 377615957

output:

278812897

result:

ok single line: '278812897'

Test #18:

score: 0
Accepted
time: 10ms
memory: 11956kb

input:

22 30 2 163686233

output:

19517828

result:

ok single line: '19517828'

Test #19:

score: 0
Accepted
time: 4ms
memory: 10872kb

input:

20 29 2 785657729

output:

713061509

result:

ok single line: '713061509'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

24 29 1 374090597

output:

312615700

result:

ok single line: '312615700'

Subtask #5:

score: 15
Accepted

Test #21:

score: 15
Accepted
time: 11ms
memory: 19868kb

input:

29 38 2 909155077

output:

745973305

result:

ok single line: '745973305'

Test #22:

score: 0
Accepted
time: 35ms
memory: 32368kb

input:

40 40 2 1067474879

output:

995503334

result:

ok single line: '995503334'

Test #23:

score: 0
Accepted
time: 16ms
memory: 21760kb

input:

32 37 2 751116719

output:

699924081

result:

ok single line: '699924081'

Test #24:

score: 0
Accepted
time: 23ms
memory: 24488kb

input:

33 37 2 496100951

output:

21741458

result:

ok single line: '21741458'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

34 38 1 499914887

output:

386116226

result:

ok single line: '386116226'

Subtask #6:

score: 10
Accepted

Test #26:

score: 10
Accepted
time: 211ms
memory: 135660kb

input:

57 66 2 767174999

output:

315351738

result:

ok single line: '315351738'

Test #27:

score: 0
Accepted
time: 217ms
memory: 124992kb

input:

52 69 2 399947623

output:

237685494

result:

ok single line: '237685494'

Test #28:

score: 0
Accepted
time: 231ms
memory: 151132kb

input:

63 64 2 903693961

output:

520250635

result:

ok single line: '520250635'

Test #29:

score: 0
Accepted
time: 325ms
memory: 189916kb

input:

65 70 2 268454909

output:

255864893

result:

ok single line: '255864893'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

58 68 1 562105223

output:

175445185

result:

ok single line: '175445185'

Subtask #7:

score: 0
Memory Limit Exceeded

Test #31:

score: 0
Memory Limit Exceeded

input:

96 96 2 453296971

output:

222864385

result: