QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620390#2438. Minimum Spanning TreesAfterlife#RE 0ms0kbC++205.1kb2024-10-07 17:54:362024-10-07 17:54:37

Judging History

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

  • [2024-10-07 17:54:37]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-07 17:54:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n , k;
int p[6];
int s[6];
int fpow(int a,int b) {
    int ans = 1;
    while(b) {
        if(b & 1) ans = 1LL * ans * a %mod;
        a = 1LL * a * a  %mod ; b >>= 1;
    }
    return ans;
}
typedef vector<int> poly;
poly operator * (const poly &a,const poly& b) {
    poly c(a.size() + b.size() - 1);
    for(int i = 0;i < a.size();i++) {
        for(int j = 0;j < b.size();j++) {
            c[i + j] = (c[i + j] + 1LL * a[i] * b[j]) % mod;
        }
    }
    return c;
}
poly operator + (const poly &a,const poly& b) {
    poly c(max(a.size() , b.size()));
    for(int i = 0;i < a.size();i++) c[i] = a[i];
    for(int i = 0;i < b.size();i++) c[i] = (c[i] + b[i]) % mod;
    return c;
}
poly operator * (const poly &a,int b) {
    poly c(a);
    for(int i = 0;i < c.size();i++) c[i] = 1LL * c[i] * b % mod;
    return c;
}
int t[45] , rt[45];

poly h[5][41];
poly f[5][41][41];
poly g[41][41];

poly mul(const poly& a,int d) {
    poly c(a.size() + d) ;
    for(int i = 0;i < a.size();i++) c[i + d] = a[i];
    return c;
}
void solv() {
    cin >> n>> k;
    int r100 = fpow(100 , mod - 2);
    for(int i = 0;i <= k;i++) {
        cin >> p[i]; p[i] = 1LL * p[i] * r100 % mod;
    }
    s[k + 1] = p[0];
    for(int i = k;i >= 0;i--) s[i] = (s[i + 1] + p[i]) % mod;
    t[0] = rt[0] = 1;
    for(int i = 1;i <= n;i++) t[i] = 1LL * t[i - 1] * i % mod , rt[i] = fpow(t[i] , mod-2);
    h[0][1] = vector<int>(1 , 1) ;

    for(int i = 1;i <= k;i++) {
        vector<vector<int>> p0(n+1 , vector<int>(n+1)) , p1(n+1 , vector<int>(n+1)) , p2(n + 1 , vector<int>(n + 1));
        for(int x = 0 ; x <= n;x++) {
            for(int y = 0;y <= n;y++) {
                p1[x][y] = (fpow(s[i] , x * y) - fpow(s[i + 1] , x * y) + mod) % mod;
                p0[x][y] = fpow(s[i + 1] , x * y) ;
                p2[x][y] = (p0[x][y] + p1[x][y]) % mod;
                // printf("%d %d : %d %d\n",x,y,p0[x][y],p1[x][y]);
            }
        }
        for(int s = 1 ; s <= n;s++) {
            for(int x = 1 ; x <= s ; x++) {
                int y = s - x; f[i][x][y].clear() ;
            }
        }
        for(int x = 1 ; x <= n;x++) f[i][x][0] = h[i - 1][x] * rt[x - 1] ;
        for(int s = 1 ; s <= n;s++) {
            for(int x = 1;x <= s;x++) {
                int y = s - x;
                if(!f[i][x][y].size()) continue ;
                int lft = n - s;
                for(int mx = 0; mx <= lft;mx++) for(int u = 0 ; u <= lft;u++) g[mx][u].clear() ;
                g[0][0] = vector<int>(1 , 1);
                for(int mx = 0 ; mx < lft ; mx++) { /// mx
                    for(int u = 0 ; u <= lft ; u++) { 
                        if(!g[mx][u].size()) continue ;
                        // printf("%d %d\n" , mx , u) ;
                        poly L = mul(h[i - 1][mx + 1] * rt[mx + 1] * p0[mx + 1][y] * p1[mx + 1][x] , i - 1);
                        poly Lk(1 , 1);
                        // if(mx == 1 && u == 0 && i == 2 && x == 1 && y == 0) {
                        //     printf("L : ");
                        //     for(auto x : L) printf("%d ",x) ;
                        //     printf("\n");
                        // }
                        for(int j = 0 ; j * (mx + 1) + u <= lft ; j++) {
                            g[mx + 1][u + j * (mx + 1)] = g[mx + 1][u + j*(mx + 1)] + g[mx][u] * Lk * rt[j] ;
                            // printf("J %d : %d %d\n",j,mx + 1, u + j * (mx + 1));
                            if((j + 1) * (mx + 1) + u <= lft) {Lk = Lk * L * p2[mx + 1][u + j * (mx + 1)]; }
                        }
                        // puts("OK") ;
                        // for(int d = max(1,mx) ; d + u <= lft ; d++) {
                        //     /// to g[d + u][d]
                        //     g[d + u][d] = g[d + u][d] + mul(g[u][mx] * h[i - 1][d] * rt[d] * p0[d][y] * p1[d][x] , i - 1) ;
                        // }
                    }
                }
                // printf("%d %d : ",x,y);
                // for(auto x : f[i][x][y]) printf("%d ",x) ; printf("\n");
                    
                
                // vector<poly> t(n + 1) ;
                for(int u = 1 ; u <= lft ; u++) {
                    // for(int i = 1;i <= u;i++) {
                    //     t[u] = t[u] + g[i][u] ;
                    // }
                    // printf("goto %d : ",u);
                    // for(auto x : g[u][u]) printf("%d ",x) ; printf("\n");
                
                    f[i][u][x + y] = f[i][u][x + y] + f[i][x][y] * g[u][u];
                }
            }
        }
        
        for(int x = 1;x <= n;x++) {
            h[i][x].clear() ;
            for(int a = 1 ; a <= x;a++) {
                h[i][x] = h[i][x] + f[i][a][x - a] * t[x - 1];
            }
        }
    }
    for(int s = 0 ; s <= (k - 1) * (n - 1) ; s++) {
        cout << h[k][n][s] <<' ' ;
    }
    cout << '\n';
    return ;
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0);
    int t;cin >> t;
    while(t--) solv() ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

200
3 1
50 50
3 2
0 50 50
3 3
25 25 25 25
8 1
41 59
7 3
37 30 7 26
3 3
16 12 18 54
9 2
9 43 48
9 3
3 40 42 15
9 1
29 71
9 2
40 42 18
5 1
76 24
5 1
39 61
9 2
23 38 39
10 4
18 15 34 2 31
7 2
23 28 49
9 4
15 13 25 19 28
7 1
64 36
6 1
50 50
9 1
4 96
4 1
64 36
9 2
24 45 31
9 2
3 61 36
9 1
65 35
8 4
6 1 3...

output:


result: