QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398640#2573. Two PermutationsPYD1AC ✓305ms59900kbC++141.8kb2024-04-25 16:03:222024-04-25 16:03:28

Judging History

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

  • [2024-04-25 16:03:28]
  • 评测
  • 测评结果:AC
  • 用时:305ms
  • 内存:59900kb
  • [2024-04-25 16:03:22]
  • 提交

answer

#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <time.h>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <stdio.h>
#include <iomanip>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mk make_pair
#define fi first
#define se second

inline int read(){
	int t = 0,f = 1;
	register char c = getchar();
	while (c < 48 || c > 57) f = (c == '-') ? (-1) : (f),c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return f * t;
}

const int N = 150 + 3,MOD = 1e9 + 7;
int n,k;
ll dp[2][N][N * N],C[N][N];

inline void add(ll &x,ll v) {x += v;if (x >= MOD) x -= MOD;}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	n = read(),k = read();
	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]) % MOD;
	}
	int lst = 1,cur = 0,s = n * n;
	dp[cur][0][0] = 1;
	for (int i = 1;i <= n;i++){
		lst ^= 1,cur ^= 1;
		memset(dp[cur],0,sizeof(dp[cur]));
		for (int j = 0;j <= n;j++){
			for (int k = 0;k <= s;k++){
				if (!dp[lst][j][k]) continue;
				ll v = dp[lst][j][k];
				add(dp[cur][j + 1][k],v);//孤立点
				add(dp[cur][j][k + i],v);//自环
				add(dp[cur][j][k + i],v * j * 2ll % MOD);//接到一个链上
				if (j >= 2) add(dp[cur][j - 1][k + 2 * i],v * j % MOD * (j - 1) % MOD);//合并两个链
				if (j) add(dp[cur][j - 1][k + 2 * i],v * j % MOD);//链->环
			}
		}
	}
	ll fct = 1;
	for (int i = 1;i <= n;i++) fct = fct * i % MOD;
	printf("%lld\n",dp[cur][0][k] * fct % MOD);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 59692kb

input:

2 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

3 7

output:

12

result:

ok 1 number(s): "12"

Test #3:

score: 0
Accepted
time: 3ms
memory: 59732kb

input:

4 10

output:

24

result:

ok 1 number(s): "24"

Test #4:

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

input:

4 14

output:

96

result:

ok 1 number(s): "96"

Test #5:

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

input:

5 10

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 11ms
memory: 59700kb

input:

5 15

output:

120

result:

ok 1 number(s): "120"

Test #7:

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

input:

5 21

output:

2400

result:

ok 1 number(s): "2400"

Test #8:

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

input:

6 21

output:

720

result:

ok 1 number(s): "720"

Test #9:

score: 0
Accepted
time: 7ms
memory: 59792kb

input:

6 30

output:

25920

result:

ok 1 number(s): "25920"

Test #10:

score: 0
Accepted
time: 3ms
memory: 59672kb

input:

6 27

output:

106560

result:

ok 1 number(s): "106560"

Test #11:

score: 0
Accepted
time: 26ms
memory: 59732kb

input:

20 300

output:

644873710

result:

ok 1 number(s): "644873710"

Test #12:

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

input:

20 139

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 42ms
memory: 59796kb

input:

30 470

output:

491424690

result:

ok 1 number(s): "491424690"

Test #14:

score: 0
Accepted
time: 43ms
memory: 59860kb

input:

30 500

output:

8436035

result:

ok 1 number(s): "8436035"

Test #15:

score: 0
Accepted
time: 59ms
memory: 59808kb

input:

40 1000

output:

617159088

result:

ok 1 number(s): "617159088"

Test #16:

score: 0
Accepted
time: 56ms
memory: 59756kb

input:

40 900

output:

729805907

result:

ok 1 number(s): "729805907"

Test #17:

score: 0
Accepted
time: 99ms
memory: 59856kb

input:

60 1830

output:

16340084

result:

ok 1 number(s): "16340084"

Test #18:

score: 0
Accepted
time: 100ms
memory: 59900kb

input:

60 2000

output:

832198921

result:

ok 1 number(s): "832198921"

Test #19:

score: 0
Accepted
time: 294ms
memory: 59860kb

input:

100 5050

output:

437918130

result:

ok 1 number(s): "437918130"

Test #20:

score: 0
Accepted
time: 305ms
memory: 59892kb

input:

100 700

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: 0
Accepted
time: 298ms
memory: 59812kb

input:

100 10000

output:

0

result:

ok 1 number(s): "0"