zoukankan      html  css  js  c++  java
  • 【LOJ】#2264. 「CTSC2017」吉夫特

    题解

    根据一番认真严肃的猜结论和打表证明之后
    我们可以得到
    (f[i] = (sum_{a[i] & a[j] == a[j]} f[j]) + 1)
    统计所有的(f[i] - 1)

    然后对于这道题,我们可以从值域上直接做

    就是(g[a])表示(a)作为结尾的数的序列有多少个

    每次从(a)转移到(a)的子集(b),同时要满足(pos[b] > pos[a])

    代码

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define MAXN 240005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
        }
        while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) out(x / 10);
        putchar('0' + x % 10);
    }
    const int MOD = 1000000007;
    int N;
    int a[MAXN],pos[MAXN],ans,f[MAXN];
    int inc(int a,int b) {
        return a + b >= MOD ? a + b - MOD : a + b;
    }
    int mul(int a,int b) {
        return 1LL * a * b % MOD;
    }
    void update(int &x,int y) {
        x = inc(x,y);
    }
    void Solve() {
        int t = 0;
        read(N);
        for(int i = 1 ; i <= N ; ++i) {
    	read(a[i]);pos[a[i]] = i;t = max(t,a[i]);
        }
        
        for(int S = t ; S ; --S) {
    	if(!pos[S]) continue;
    	update(ans,f[S]);
    	update(f[S],1);
    	for(int T = (S - 1) & S ; T ; T = (T - 1) & S) {
    	    if(!pos[T]) continue;
    	    if(pos[T] > pos[S]) update(f[T],f[S]);
    	}
        }
        out(ans);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    
  • 相关阅读:
    键盘记录器,可截获到 QQ 的password
    《python源代码剖析》笔记 pythonm内存管理机制
    Unity 捕获IronPython脚本错误
    POJ 3020 Antenna Placement 最大匹配
    XCL-Charts画线图(Line Chart)
    android设置背景色为透明
    设计时属性文件
    Windows Mobile基础
    Wince 的CAB安装包
    惠普的 ipaq112 恢复出厂设置
  • 原文地址:https://www.cnblogs.com/ivorysi/p/9811336.html
Copyright © 2011-2022 走看看