题目传送门

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

https://loj.ac/problem/2264

http://uoj.ac/problem/300

题解

真 - 签到题。

对于一个组合数,直接进行 Luca 定理。
\[\binom nm = \binom {\frac n2}{\frac m2} \binom {n \bmod 2}{m\bmod 2}\]
可以发现,对于每一个二进制位,如果出现 \((0, 1)\) 这样的组合,那么整个组合数就是 \(0\),否则就是 \(1\)

所以 \(\binom nm = 1\) 的充要条件就是 \(m \subseteq n\)

那么把问题放到序列上,对于一位求出答案以后,扫描其所有子集更新。


因为 \(a_i\) 两两不同,所以复杂度可以保证为 \(O(3^{\log_2 a_i})\)

#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;
}

const int N = 211985 + 7;
const int M = 233333 + 7;
const int P = 1e9 + 7;

int n, m;
int a[N], dp[M];

inline int smod(int x) { return x >= P ? x - P : x; }
inline void sadd(int &x, const int &y) { x += y; x >= P ? x -= P : x; }
inline int fpow(int x, int y) {
    int ans = 1;
    for (; y; y >>= 1, x = (ll)x * x % P) if (y & 1) ans = (ll)ans * x % P;
    return ans;
}

inline void work() {
    int ans = 0;
    for (int i = 1; i <= m; ++i) dp[i] = 1;
    for (int i = 1; i <= n; ++i) {
        int s = a[i];
        sadd(ans, dp[s] - 1);
        int tmp = dp[s];
        for (int sta = s; sta; sta = (sta - 1) & s) sadd(dp[sta], tmp);
    }
    printf("%d\n", ans);
}

inline void init() {
    read(n);
    for (int i = 1; i <= n; ++i) read(a[i]), smax(m, a[i]);
}

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