QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232842#6410. Classical DP ProblembiancaRE 0ms0kbC++141.3kb2023-10-30 23:35:322023-10-30 23:35:33

Judging History

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

  • [2023-10-30 23:35:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-30 23:35:32]
  • 提交

answer

#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;
#define MaxN 5000
#define MOD 998244353

int a[MaxN], b[MaxN];
int dp[MaxN][MaxN];


int dinamic(int a[], int k, int x)
{
    dp[0][x]=1;
    int i, j;
    for(i=0; i<k; i++)
    {
        for(j=x; j>=0; j--)
        {
            dp[i+1][j]+=(a[i+1]-j)*dp[i][j];
            dp[i+1][j]%=MOD;
            if(j>0)
            {
                dp[i+1][j-1]+=j*dp[i][j];
                dp[i+1][j-1]%=MOD;
            }

        }
    }
    return dp[k][0];
}

int fact(int k)
{
    int prod=1;
    while(k>0)
    {
        prod=prod*k;
        prod%=MOD;
        k--;
    }
}
int main()
{
    int n, i, j, k, x=0, res;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
    }

    k=1;
    while(n-k>a[k])
    {
        k++;
    }
    cout<<k<<" ";
    reverse(a+1, a+n+1);

    x=a[k+1];
    res+=dinamic(a, k, x);

    for(i=n; i>0; i--)
    {
        j=1;
        while(a[j]>=i)
        {
            j++;
        }
        b[i]=j-1;
    }

    x=b[k+1];

    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            dp[i][j]=0;
        }
    }
    res+=dinamic(b, k, x);
    res%=MOD;
    res-=fact(k);
    cout<<res;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
1 2 3

output:

2 

result: