QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20442#2573. Two PermutationsAppleblue17#AC ✓1031ms24512kbC++17792b2022-02-16 10:02:412022-05-03 09:55:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 09:55:27]
  • 评测
  • 测评结果:AC
  • 用时:1031ms
  • 内存:24512kb
  • [2022-02-16 10:02:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long N=110,mod=1e9+7,inv2=(mod+1)/2;

long long n,m;
long long dp[2][N][N*N],id;

void gmod(long long &x){
	x%=mod;
}

int main(){
	cin>>n>>m;
	dp[0][0][0]=1;
	for(long long i=1;i<=n;i++){
		id^=1;
		memset(dp[id],0,sizeof(dp[id]));
		for(long long j=0;j<=n;j++){
			for(long long k=0;k<=m;k++){
				long long s=i-1-j,emp=n-(2*s+j);
				if(emp>0 && j+1<=n && k+i<=m) gmod(dp[id][j+1][k+i]+=dp[id^1][j][k]*emp%mod);
				if(emp>0) gmod(dp[id][j][k]+=dp[id^1][j][k]*emp%mod*(emp-1)%mod);
				if(s>0 && j+2<=n && k+2*i<=m) gmod(dp[id][j+2][k+2*i]+=dp[id^1][j][k]*s%mod*s%mod);
				if(s>0 && emp>0 && j+1<=n && k+i<=m) gmod(dp[id][j+1][k+i]+=dp[id^1][j][k]*s%mod*emp%mod*2%mod);
			}
		}
	}
	cout<<dp[id][n][m];
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 24248kb

input:

2 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

3 7

output:

12

result:

ok 1 number(s): "12"

Test #3:

score: 0
Accepted
time: 9ms
memory: 24336kb

input:

4 10

output:

24

result:

ok 1 number(s): "24"

Test #4:

score: 0
Accepted
time: 9ms
memory: 24460kb

input:

4 14

output:

96

result:

ok 1 number(s): "96"

Test #5:

score: 0
Accepted
time: 8ms
memory: 24368kb

input:

5 10

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 9ms
memory: 24392kb

input:

5 15

output:

120

result:

ok 1 number(s): "120"

Test #7:

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

input:

5 21

output:

2400

result:

ok 1 number(s): "2400"

Test #8:

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

input:

6 21

output:

720

result:

ok 1 number(s): "720"

Test #9:

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

input:

6 30

output:

25920

result:

ok 1 number(s): "25920"

Test #10:

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

input:

6 27

output:

106560

result:

ok 1 number(s): "106560"

Test #11:

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

input:

20 300

output:

644873710

result:

ok 1 number(s): "644873710"

Test #12:

score: 0
Accepted
time: 28ms
memory: 24360kb

input:

20 139

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 51ms
memory: 24364kb

input:

30 470

output:

491424690

result:

ok 1 number(s): "491424690"

Test #14:

score: 0
Accepted
time: 55ms
memory: 24444kb

input:

30 500

output:

8436035

result:

ok 1 number(s): "8436035"

Test #15:

score: 0
Accepted
time: 77ms
memory: 24472kb

input:

40 1000

output:

617159088

result:

ok 1 number(s): "617159088"

Test #16:

score: 0
Accepted
time: 70ms
memory: 24384kb

input:

40 900

output:

729805907

result:

ok 1 number(s): "729805907"

Test #17:

score: 0
Accepted
time: 148ms
memory: 24380kb

input:

60 1830

output:

16340084

result:

ok 1 number(s): "16340084"

Test #18:

score: 0
Accepted
time: 156ms
memory: 24512kb

input:

60 2000

output:

832198921

result:

ok 1 number(s): "832198921"

Test #19:

score: 0
Accepted
time: 607ms
memory: 24472kb

input:

100 5050

output:

437918130

result:

ok 1 number(s): "437918130"

Test #20:

score: 0
Accepted
time: 224ms
memory: 24380kb

input:

100 700

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 1031ms
memory: 24376kb

input:

100 10000

output:

0

result:

ok 1 number(s): "0"