QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232864#6410. Classical DP ProblembiancaWA 0ms3716kbC++141.3kb2023-10-30 23:50:392023-10-30 23:50:39

Judging History

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

  • [2023-10-30 23:50:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3716kb
  • [2023-10-30 23:50:39]
  • 提交

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--;
    }
    return prod;
}
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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3716kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3588kb

input:

2
2 2

output:

1 -1

result:

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