zoukankan      html  css  js  c++  java
  • loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】

    题目链接

    loj300

    题解

    orz litble
    膜完题解后,突然有一个简单的想法:
    考虑到(2)是质数,考虑Lucas定理:

    [{n choose m} = prod_{i = 1} {lfloor frac{n}{2^{i - 1}} floor mod 2^i choose lfloor frac{m}{2^{i - 1}} floor mod 2^i} pmod 2 ]

    [{n choose m} = prod_{each.bit.of.n.and.m} {n' choose m'} pmod 2 ]

    如果二进制下有任何一位(n)(0)(m)不为(0),那么就会出现(m' > n')的项,结果就为(0)
    所以结果不为(0),当且仅当二进制下(m)(n)的子集

    所以枚举子集dp即可【(f[i])表示以(A[u] = i)(u)开头的合法子序列个数】
    ([1,n])枚举子集的复杂度是(O(3^{log(max{a_i})}))

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #define LL long long int
    #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
    #define REP(i,n) for (int i = 1; i <= (n); i++)
    #define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
    using namespace std;
    const int maxn = 250000,maxm = 100005,INF = 1000000000,P = 1e9 + 7;
    inline int read(){
    	int out = 0,flag = 1; char c = getchar();
    	while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
    	while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
    	return out * flag;
    }
    int f[maxn],a[maxn],ans,n;
    int main(){
    	n = read();
    	REP(i,n) a[i] = read();
    	for (int i = n; i; i--){
    		int u = a[i];
    		for (int j = u; j; j = (j - 1) & u){
    			f[u] = (f[u] + f[j]) % P;
    		}
    		ans = (ans + f[u]) % P;
    		f[u]++;
    	}
    	printf("%d
    ",ans);
    	return 0;
    }
    
    
  • 相关阅读:
    Docker
    java 8 特性
    RISC-V: custom instruction and its simulation(转)
    如何在GCC中添加一条RISC-V指令(转)
    The GNU MCU Eclipse RISC-V Embedded GCC build
    Adding custom instruction to RISCV ISA and running it on gem5 and spike(转)
    How to add a custom instruction to the RISC-V GCC tools?(转)
    Adding and using a new instruction
    vuex2
    jq 显示/隐藏 某个模块
  • 原文地址:https://www.cnblogs.com/Mychael/p/8987024.html
Copyright © 2011-2022 走看看