QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232843#6410. Classical DP ProblemelisaipateWA 0ms5688kbC++141.0kb2023-10-30 23:36:242023-10-30 23:36:25

Judging History

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

  • [2023-10-30 23:36:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5688kb
  • [2023-10-30 23:36:24]
  • 提交

answer

#include <iostream>

using namespace std;
#define nmax 5001
#define mod 998244353


int lin[nmax], col[nmax];
long long dp[2][nmax][nmax], n, k;

void fctdp( int ind, int a[] ) {
    int i, j;
    for( i = 0; i < k; i++ ) {
        for( j = 0; j < k; j++ ) {
            dp[ind][i+1][j] +=  (a[i+1] - j) * dp[ind][i][j] % mod;
            if( j >= 1 )
                dp[ind][i+1][j-1] += j*dp[ind][i][j] % mod;
        }
    }
}


int main()
{
    int i, nr;
    long long fact;
    cin >> n;
    for( i = n; i >= 1; i-- )
        cin >> lin[i];

    nr = n;
    for( i = 1; i <= n; i++) {
        while( lin[nr] < i )
            nr--;
        col[i] = nr;
    }


    k = 1;
    while( lin[k] >= k )
        k++;
    k--;


    dp[0][0][lin[k+1]] = 1;

    dp[1][0][col[k+1]] = 1;


    fctdp( 0, lin );
    fctdp( 1, col );



    fact = 1;
    for( i = 2; i <= k; i++ )
        fact = fact * i % mod;

    cout << dp[0][k][0] + dp[1][k][0] - fact;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 3

output:

6

result:

wrong answer 1st numbers differ - expected: '2', found: '6'