QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797766#9647. 数位 DPDanielQOJCompile Error//C++143.2kb2024-12-03 17:51:282024-12-03 17:51:29

Judging History

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

  • [2024-12-03 17:51:29]
  • 评测
  • [2024-12-03 17:51:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
int n, k, q;
string s;
int a[1005];
ui ksm(ui x, int y){
    ui ans = 1;
    while(y){
        if(y&1)ans = ans * x;
        y >>= 1;
        x = x * x;
    }
    return ans;
}
int c[1005];
ui ans;
int m;
ui dp[1005][1<<16];
int p[1<<16];
ui KSM[1005][105];
ui ANS[55][1<<16][17];
bool vis[55][1<<16][17];
int rk[1005];
int ord[1005];
ui calc(int n, int m, int K, int bh){
    if(vis[ord[n]][m][K]){
        return ANS[ord[n][m][K]];
    }
    ui ans = 0;
    for(int i = (n?min(31/n,K - 1):K-1); i >= 0; i--){
        if(m>>i&1){
            int num = __builtin_popcount(m>>i+1);
            if(1ll * i * n < 32){
                ans += ((ui)1 << i * n) * KSM[bh][num];
            }
        }
    }
    ans = -ans;
    if(1ll * K * n < 32)ans += (ui)1<<K*n;
    vis[ord[n]][m][K] = 1;
    return ANS[ord[n]][m][K] = ans;
}
signed main(){
    // freopen("dp.in", "r", stdin);
    // freopen("dp.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> k >> q;
    cin >> s;
    int ok = 1;
    for(auto i : s){
        if(i == 'A')ok = 0;
    }
    if(ok){
        while(q--){
            cin >> m;
            int bh = -1, K = k;
            ui ans = 0;
            for(int i = (n?min(31/n,K - 1):K-1); i >= 0; i--){
                if(m>>i&1){
                    int num = __builtin_popcount(m>>i+1);
                    if(1ll * i * n < 32){
                        ans += ((ui)1 << i * n) * (bh==-1?ksm(n,num): KSM[bh][num]);
                    }
                }
            }
            ans = -ans;
            if(1ll * K * n < 32)ans += (ui)1<<K*n;
            cout << ans << '\n';
        }
        return 0;
    }
    for(int i = 0; i < 1<<16; i++){
        p[i] = k;
        for(int j = 0; j < 16; j++){
            if(i>>j&1){
                p[i] = j;
                break;
            }
        }
    }
    vector<int>vec;
    set<int>st;
    for(int i = 1; i <= n; i++){
        int en = i;
        while(en + 1 <= n && s[en-1] != 'A')en++;
        vec.emplace_back(en - i + 1);
        i = en;
    }
    for(int i = 1; i <= vec.size(); i++){
        for(int j = 0; j <= k; j++){
            KSM[i][j] = ksm(vec[i-1] - (i!=1), j);
        }
        st.insert(vec[i-1]-(i!=1));
    }
    vector<int>vecc;
    for(auto i : st){
        vecc.emplace_back(i);
        ord[i] = vecc.size() - 1;
    }
    while(q--){
        cin >> m;
        for(int i = 0; i <= vec.size(); i++){
            for(int j = 0; j < (1<<k); j++){
                dp[i][j] = 0;
            }
        }
        dp[vec.size()][m] = 1;
        for(int i = vec.size(); i >= 1; i--){
            for(int j = 0; j < (1<<k); j++){
                if(!dp[i][j])continue;
                for(int w = j; ; w = (w-1) & j){
                    int num = __builtin_popcount((j^w) >> p[w]);
                    dp[i - 1][w] += dp[i][j] * KSM[i][num] * calc(vec[i-1] - (i!=1), (j^w) & (1<<p[w])-1, p[w], i) * (i==1?1:(ui)(((ui)1<<k)-w));
                    if(!w)break;
                }
            }
        }
        cout << dp[0][0] << '\n';
    }
    return 0;
}

Details

answer.code: In function ‘unsigned int calc(int, int, int, int)’:
answer.code:29:26: error: invalid types ‘int[int]’ for array subscript
   29 |         return ANS[ord[n][m][K]];
      |                          ^