UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211786#37. 染色yiweixxs51567ms21584kbC++869b2024-10-02 16:35:222024-10-02 16:35:24

answer

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<list>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
int n,m,P;
int f[5005][5005];
int main(){
    cin>>n>>m>>P;
    f[1][1]=m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<min(i+1,m);j++){
            for(int k=1;k<=j;k++){
                f[i+1][k]+=f[i][j];
                f[i+1][k]%=P;
            }
            if(j<m-1)f[i+1][j+1]+=f[i][j]*(m-1);
            f[i+1][j+1]%=P;
        }
    }
    int ans=0;
    for(int i=1;i<m;i++){
        ans+=f[n][i];
        ans%=P;
    }
    cout<<ans;
    return 0;
}
/*
1 1
f[i][j] 前i个格子中,最后j格颜色各不相同
j<m-1
    f[i][j]->f[i+1][1~j+1];
j=m-1
    f[i][j]->f[i+1][1~j];
*/



Details

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

Test #1:

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

input:

5 2 6

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1236kb

input:

8 8 562455908

output:

63541640

result:

wrong answer 1st numbers differ - expected: '16736896', found: '63541640'

Test #3:

score: 0
Wrong Answer
time: 3ms
memory: 9020kb

input:

1942 7 873185963

output:

149510765

result:

wrong answer 1st numbers differ - expected: '41441893', found: '149510765'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 9396kb

input:

2030 10 187301366

output:

134346248

result:

wrong answer 1st numbers differ - expected: '171496026', found: '134346248'

Test #5:

score: 0
Wrong Answer
time: 7ms
memory: 19928kb

input:

4643 9 998244353

output:

-819347396

result:

wrong answer 1st numbers differ - expected: '583546139', found: '-819347396'

Test #6:

score: 0
Wrong Answer
time: 1492ms
memory: 11092kb

input:

1447 3969 998244353

output:

17278375

result:

wrong answer 1st numbers differ - expected: '669602806', found: '17278375'

Test #7:

score: 0
Wrong Answer
time: 5ms
memory: 2228kb

input:

226 212 998244352

output:

458435552

result:

wrong answer 1st numbers differ - expected: '503316480', found: '458435552'

Test #8:

score: 0
Wrong Answer
time: 15ms
memory: 2604kb

input:

300 292 779230672

output:

-585851604

result:

wrong answer 1st numbers differ - expected: '95153840', found: '-585851604'

Test #9:

score: 0
Wrong Answer
time: 11ms
memory: 2444kb

input:

269 228 479932618

output:

385673558

result:

wrong answer 1st numbers differ - expected: '244481530', found: '385673558'

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 2152kb

input:

216 112 207794912

output:

188892128

result:

wrong answer 1st numbers differ - expected: '145540448', found: '188892128'

Test #11:

score: 0
Wrong Answer
time: 10ms
memory: 2556kb

input:

291 261 37264436

output:

-32922663

result:

wrong answer 1st numbers differ - expected: '28883269', found: '-32922663'

Test #12:

score: 0
Wrong Answer
time: 11ms
memory: 2456kb

input:

273 218 960539553

output:

215483011

result:

wrong answer 1st numbers differ - expected: '718739009', found: '215483011'

Test #13:

score: 0
Time Limit Exceeded

input:

2991 2318 704783019

output:


result:


Test #14:

score: 0
Time Limit Exceeded

input:

4413 790 693631006

output:


result:


Test #15:

score: 0
Time Limit Exceeded

input:

4786 4581 2

output:


result:


Test #16:

score: 0
Time Limit Exceeded

input:

4953 4424 876277826

output:


result:


Test #17:

score: 0
Wrong Answer
time: 13ms
memory: 21584kb

input:

4921 37 699201223

output:

-191293912

result:

wrong answer 1st numbers differ - expected: '206663263', found: '-191293912'

Test #18:

score: 0
Time Limit Exceeded

input:

4991 994 533908193

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

5000 5000 640462742

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

4935 1005 961254358

output:


result: