QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232827#6410. Classical DP ProblemLaurraTL 0ms0kbC++141.4kb2023-10-30 23:16:042023-10-30 23:16:05

Judging History

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

  • [2023-10-30 23:16:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-30 23:16:04]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;

#define MOD 998244353
#define dim 5002
#define ll long long
vector<int> v;
int n;
bool ok(int i,int j)
{
    if(i>=1 && v[i]>=j)
        return true;
}
int dp[dim][dim];
ll fact(int k)
{
    ll p=1,i;
    for(i=2;i<=k;i++)
        p*=i;
    return p;
}
void init()
{
    int i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
            dp[i][j]=0;
    }
}
ll calc(int k)
{
    int x=v[k+1],i,j;
    dp[0][x]=1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<=x;j++)
        {
            if(j)
            {
                dp[i+1][j-1]=(dp[i+1][j-1]+j*dp[i][j])%MOD;
            }
            dp[i+1][j]=(dp[i+1][j]+(v[i+1]-j)*dp[i][j])%MOD;
        }
    }
    return dp[k][0];
}
void flip()
{
    vector<int> v2(n+1);
    int i,j;
    for(i=1;i<=n;i++)
    {
        j=1;
        while(j<=n && v[j]>=i)
            j++;
        v2[i]=j-1;
    }
    v=v2;
}

int main()
{
    int k,j,i;
    ll tot=0;
    //Citire
    cin>>n;
    v.resize(n+1);
    for(i=1;i<=n;i++)
    {
        cin>>v[n-i+1];
    }
    //Calc nr ture
    k=0;
    j=1;
    i=1;
    while(ok(i,j)==true)
    {
        i++;
        j++;
        k++;
    }
    cout<<k<<" ";
    tot=-fact(k);
    //Dinamica
    init();
    tot+=calc(k);
    flip();
    init();
    tot+=calc(k);
    cout<<tot;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
1 2 3

output:


result: