bzoj4036 [HAOI2015]ビット単位またはフォームおよび除外圧DP +のMinMax

トピックポータル

https://lydsy.com/JudgeOnline/problem.php?id=4036

問題の解決策

なる(2 ^ N-1 \を\する ) 各桁が明らかに出現していることを意味します。

その後のMinMax撥能力によって、問題がためにセットに変換することができます\(S \)求めて、\(S \)少なくとも一つの要素が表示される確率を。

この問題は見つけることと等価です\(S \)は番号の発生確率のいずれかの要素が含まれていないことです表示されます\(S \)補数のサブセットの確率。

これは、時間の複雑さの実現SoSDPによって求められることができ(O(\)^ N- N2)\を


SoSDPについて

この事はできます\(O(N2 ^ n)は \) の順序で決定された\(S \)値のサブセットのコレクションに。

順序は\(F [i]が[S ] \) を表し\(S \)のみ\(Iは\)以下のビットに(1 \)は\となる(0 \)\右の"サブセット"値そして、。

従ってもし\(私はS \で\)、次いで\(F [I] [S] = F [I - 1] [S] + F [I - 1] [S - \ {Iが\}] \)

否则 \(f[i][S] = f[i - 1][S]\)

最後に\(F [N] [S ] \) される(S \)\は、サブセットに答えます。あなたは、スクロール次元配列の最適化を使用することができ、


この質問コード:

#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I> inline void read(I &x) {
    int f = 0, c;
    while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
    x = c & 15;
    while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
    f ? x = -x : 0;
}

#define lowbit(x) ((x) & -(x))

const int N = 20 + 7;
const int M = (1 << 20) + 7;

int n, S;
double f[M];
int p[M];

inline void work() {
    for (int i = 0; i < n; ++i)
        for (int s = 1; s <= S; ++s)
            if ((s >> i) & 1) f[s] += f[s ^ (1 << i)];
    for (int i = 1; i <= S; ++i) if (f[S] == f[S ^ i]) {
        puts("INF");
        return;
    }
    for (int s = 1; s <= S; ++s) p[s] = p[s ^ lowbit(s)] + 1;
    double ans = 0;
    for (int s = 1; s <= S; ++s)
        if (p[s] & 1) ans += 1 / (1 - f[S ^ s]);
        else ans -= 1 / (1 - f[S ^ s]);
    printf("%.10lf\n", ans);
}

inline void init() {
    read(n);
    S = (1 << n) - 1;
    for (int i = 0; i <= S; ++i) scanf("%lf", &f[i]);
}

int main() {
#ifdef hzhkk
    freopen("hkk.in", "r", stdin);
#endif
    init();
    work();
    fclose(stdin), fclose(stdout);
    return 0;
}

おすすめ

転載: www.cnblogs.com/hankeke/p/bzoj4036.html