QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232912#6410. Classical DP Problemiulia_morariuWA 0ms3624kbC++141.8kb2023-10-31 00:33:492023-10-31 00:33:50

Judging History

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

  • [2023-10-31 00:33:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2023-10-31 00:33:49]
  • 提交

answer

#include <bits/stdc++.h>
#define Mod 1000000007

using namespace std;

int k;
int din(vector <int> a){
    int n = a.size();
    int x = 0;
    int it = n - 1;
    x = 1;
    for(int i = n - 1; i >= 0; i--){
        if(a[i] <= k){
            x = a[i];
            break;
        }
    }


    int dp[n + 1][n + 1];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++) dp[i][j] = 0;
    }

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

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= a[k]; j++){
            // acoperim o cloana neimportanta
            dp[i + 1][j] += (a[i] - j) * dp[i][j];
            dp[i + 1][j] %= Mod;
            // acoperim o coloana importanta
            if(j > 0){
                dp[i + 1][j - 1] += j * dp[i][j];
                dp[i + 1][j - 1] %= Mod;
            }
        }
    }

    return dp[k][0];
}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);

    int n; cin >> n;
    vector <int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    reverse(v.begin(), v.end());
    k = 0;

    for(int i = 0; i < n; i++){
        bool ok = 1;
        for(int j = 0; j <= i; j++){
            if(v[j] < i + 1){
                ok = 0;
                break;
            }
        }
        if(!ok){
            k = i;
            break;
        }
    }

    cout << k << " ";


    int val1 = din(v);

    vector<int> v1(n);
    for(int i = 0; i < n; i++) v1[i] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < v[i]; j++){
            v1[j]++;
        }
    }
    reverse(v1.begin(), v1.end());

    int val2 = din(v1);

    int fact = 1;
    for(int i = 2; i <= k; i++){
        fact *= k;
        fact %= Mod;
    }

    cout << val1 + val2 - fact << endl;



    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

0 1

result:

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