UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199720#519. 分组游戏UperFicial1001918ms83292kbC++1.0kb2023-12-19 08:28:212023-12-19 12:49:57

answer

#include<bits/stdc++.h>
#define N 3100
#define mod 998244353
#define int long long
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int f[N][N],g[N][N],C[N][N],cnt[N],n;
int add(int a,int b){return (a+b)%mod;}
int mul(int a,int b){return (a*b)%mod;}
signed main()
{
	n=read();
    for(int i=1,s;i<=n;i++)
    {
    	s=read();
        cnt[s]++;
    }
    C[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        C[i][0]=1;
        for(int j=0;j<=i;j++)
        C[i][j]=add(C[i-1][j-1],C[i-1][j]);
    }
    for(int j=1;j<=n;j++)
    {
        g[0][j]=1;
        for(int i=j;i<=n;i+=j)
        g[i][j]=mul(g[i-j][j],C[i-1][j-1]);
    }
    f[n+1][0]=1;
    for(int i=n;i>=1;i--)for(int j=0;j<=n;j++)for(int k=0;k*i<=j+cnt[i];k++)
    f[i][j+cnt[i]-k*i]=add(f[i][j+cnt[i]-k*i],mul(f[i+1][j],mul(C[j+cnt[i]][k*i],g[k*i][i])));
    cout<<f[1][0]<<"\n";
    return 0;
}

详细

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

Test #1:

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

input:

10
10 8 9 1 3 6 5 5 7 3

output:

14548

result:

ok single line: '14548'

Test #2:

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

input:

50
5 27 40 10 5 46 9 17 6 12 23 41 3 37 24 26 16 17 50 9 42 25 6 34 50 19 40 47 17 28 16 21 24 50 47...

output:

64121930

result:

ok single line: '64121930'

Test #3:

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

input:

50
24 13 40 28 35 46 48 50 6 49 18 23 2 40 21 16 27 19 47 1 3 10 11 22 46 23 15 18 19 21 8 6 10 1 20...

output:

650932563

result:

ok single line: '650932563'

Test #4:

score: 10
Accepted
time: 6ms
memory: 6176kb

input:

300
203 297 19 55 127 149 228 105 201 275 277 12 77 1 105 259 274 77 274 125 164 276 217 74 29 242 1...

output:

963129383

result:

ok single line: '963129383'

Test #5:

score: 10
Accepted
time: 3ms
memory: 6172kb

input:

300
278 34 167 270 1 22 88 81 205 157 114 224 156 94 110 169 196 258 134 140 39 71 75 147 121 13 77 ...

output:

432589333

result:

ok single line: '432589333'

Test #6:

score: 10
Accepted
time: 372ms
memory: 83288kb

input:

2000
1448 1819 1531 1537 94 911 293 551 788 914 1565 456 430 313 1781 1892 1534 1296 1294 1481 520 1...

output:

826140580

result:

ok single line: '826140580'

Test #7:

score: 10
Accepted
time: 407ms
memory: 83288kb

input:

2000
1002 677 365 751 861 1332 1303 1654 1253 853 970 1165 515 342 250 291 1301 106 414 1946 1421 84...

output:

474732052

result:

ok single line: '474732052'

Test #8:

score: 10
Accepted
time: 364ms
memory: 83284kb

input:

2000
365 1326 866 1778 444 1083 454 798 762 96 17 1762 562 900 1499 81 1170 644 1103 602 71 1157 556...

output:

547036281

result:

ok single line: '547036281'

Test #9:

score: 10
Accepted
time: 381ms
memory: 83292kb

input:

2000
1697 1618 1091 656 540 1792 1788 1221 1794 303 1642 575 637 353 1519 194 693 427 1817 909 1430 ...

output:

88226629

result:

ok single line: '88226629'

Test #10:

score: 10
Accepted
time: 385ms
memory: 83284kb

input:

2000
1127 1344 1450 381 1358 623 431 912 1807 48 528 1320 483 186 1089 1051 799 1772 1686 617 1916 1...

output:

407060398

result:

ok single line: '407060398'