UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204017#2791. 历史snow_trace1001038ms135724kbC++111.5kb2024-04-02 11:13:052024-04-02 21:18:00

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int cnt[105];
int C[5205][5205];
int tt[105][105];
int dp[105][105][105];
int n,m;int a[5006],jie[5205];
signed main(){
	cin >> n;for(int i = 1;i<=n;i++)cin >> a[i];
	C[0][0] =C[1][0] = C[1][1] = 1;
	for(int i = 2;i<=5200;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;
	}//cout << C[6][3] << endl;
	jie[0] = 1;for(int i = 1;i<=5200;i++)jie[i] = jie[i-1]*i%mod;
	vector<int>p;for(int i = 1;i<=n;i++)p.push_back(a[i]);sort(p.begin(),p.end());
	p.erase(unique(p.begin(),p.end()),p.end());m = p.size();
	for(int i = 1;i<=n;i++)a[i] = lower_bound(p.begin(),p.end(),a[i])-p.begin()+1;
	//for(int i = 1;i<=n;i++)cout << a[i] << " ";cout << endl;
	for(int i = 1;i<=n;i++)cnt[a[i]]++; 
	for(int i = 1;i<=m;i++){
		for(int j =1;j<m;j++){
			tt[i][j+1] = C[cnt[i]+j-1][j]-1;
		}
	}//cout << tt[1][4] << endl;
	dp[0][0][0] = 1;dp[1][0][0] = 1;
	for(int i = 1;i<=m;i++){
		for(int j = 0;j<=m;j++){
			for(int k = 1;k<=i;k++){
				for(int y = 2;y<=j;y++){
					dp[i][j][k] = (dp[i-1][j-y][k-1]*tt[i][y]+dp[i][j][k])%mod;
				}
			}
		}memcpy(dp[i+1],dp[i],sizeof(dp[i]));
	}int ans =0;
	for(int k = 0;k<=m;k++)for(int j =0;j<=m;j++){
		ans = (ans+dp[m][j][k]*jie[k]%mod*jie[m-k]%mod)%mod;
	}//cout << ans << endl;
	for(int i = 1;i<=m;i++)ans = ans*jie[cnt[i]]%mod;
	cout << ans << endl;
	return 0;
}/* 
循环里面 y 打成 j 意外的能过一堆手造的小样例
调了一个多小时。 
*/

这程序好像有点Bug,我给组数据试试?

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 31ms
memory: 127420kb

input:

10
3 4 1 10 3 7 2 5 4 1

output:

612864

result:

ok "612864"

Test #2:

score: 10
Accepted
time: 40ms
memory: 127328kb

input:

10
4 1 2 3 7 3 2 3 8 3

output:

959616

result:

ok "959616"

Test #3:

score: 10
Accepted
time: 41ms
memory: 127760kb

input:

3000
3 3 8 2 3 5 2 2 4 1 1 3 8 1 6 7 1 1 2 10 1 9 3 3 2 3 2 2 1 3 1 1 6 1 7 10 1 9 7 2 1 3 1 2 6 3 1...

output:

111394605

result:

ok "111394605"

Test #4:

score: 10
Accepted
time: 153ms
memory: 135720kb

input:

5000
18 23 31 2 41 20 3 1 49 28 10 1 25 2 55 1 4 1 15 38 45 1 87 55 49 2 30 1 92 3 37 1 68 10 3 20 5...

output:

562512735

result:

ok "562512735"

Test #5:

score: 10
Accepted
time: 80ms
memory: 132608kb

input:

300
5 47 17 16 1 20 1 15 7 14 4 38 19 59 1 74 4 57 1 1 11 1 3 1 6 31 98 4 12 5 40 4 16 9 1 29 4 18 1...

output:

926527742

result:

ok "926527742"

Test #6:

score: 10
Accepted
time: 163ms
memory: 135408kb

input:

99
1 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3...

output:

509457672

result:

ok "509457672"

Test #7:

score: 10
Accepted
time: 145ms
memory: 135720kb

input:

5000
1 2 3 24 4 1 5 16 3 6 36 10 1 3 55 42 2 2 1 1 2 97 3 2 44 10 14 6 1 1 11 62 8 14 3 3 60 1 2 6 1...

output:

502114207

result:

ok "502114207"

Test #8:

score: 10
Accepted
time: 145ms
memory: 135720kb

input:

5000
45 9 6 3 1 5 3 56 5 24 1 26 36 3 1 56 5 21 2 24 41 3 45 24 23 13 93 1 2 4 6 3 3 2 30 4 8 1 1 3 ...

output:

434274969

result:

ok "434274969"

Test #9:

score: 10
Accepted
time: 113ms
memory: 135720kb

input:

5000
2 27 18 2 25 12 43 1 5 10 3 16 4 6 64 3 63 86 1 1 2 4 27 13 1 3 8 39 5 2 23 6 15 30 94 1 20 27 ...

output:

829057783

result:

ok "829057783"

Test #10:

score: 10
Accepted
time: 127ms
memory: 135724kb

input:

5000
3 10 4 12 49 10 1 1 14 5 10 73 4 41 56 18 16 1 4 6 2 1 5 4 14 2 7 7 32 5 34 44 14 37 48 45 2 6 ...

output:

133737347

result:

ok "133737347"

Extra Test:

score: 0
Extra Test Passed