zoukankan      html  css  js  c++  java
  • bzoj4903 & loj2264 [Ctsc2017]吉夫特 Lucas 定理+状压DP

    题目传送门

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

    https://loj.ac/problem/2264

    http://uoj.ac/problem/300

    题解

    真 - 签到题。

    对于一个组合数,直接进行 Luca 定理。

    [inom nm = inom {frac n2}{frac m2} inom {n mod 2}{mmod 2} ]

    可以发现,对于每一个二进制位,如果出现 ((0, 1)) 这样的组合,那么整个组合数就是 (0),否则就是 (1)

    所以 (inom 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
    ", 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;
    }
    
  • 相关阅读:
    行规
    不要在对抽象类接口abstract virtual什么的混淆不清了
    MQ与Webservice的区别
    Asp.net MVC流程简述
    Lambda表达式树
    mysql用户管理、权限管理
    mysql锁、事务、存储引擎、索引
    mysql新增、删除、修改
    mysql基础
    linux的任务计划与mail
  • 原文地址:https://www.cnblogs.com/hankeke/p/bzoj4903.html
Copyright © 2011-2022 走看看