• codeforces 388D Fox and Perfect Sets(线性基+数位dp)


    #include<bits/stdc++.h>
    using namespace std;
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define rep(i, a, b) for(int i=(a); i<(b); i++)
    #define sz(x) (int)x.size()
    #define de(x) cout<< #x<<" = "<<x<<endl
    #define dd(x) cout<< #x<<" = "<<x<<" "
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef vector<int> vi;
    
    const int P=1e9+7;
    int n, k;
    int a[33];
    ll f[33][33][2], pw[33];
    
    void upd(ll &a, ll b) {
    	a+=b;
    	if(a>=P) a-=P;
    }
    void init() {
    	pw[0]=1;
    	rep(i,1,33) pw[i]=pw[i-1]*2%P;
    }
    
    int main() {
    	init();
    	while(~scanf("%d",&k)) {
    		n=0;
    		while(k) {
    			a[++n]=(k&1);
    			k>>=1;
    		}
    		for(int l=1, r=n;l<r;++l, --r) swap(a[l], a[r]);
    		memset(f,0,sizeof(f));
    		f[0][0][1]=1;
    		rep(i,0,n) rep(j,0,i+1) {
    			if(f[i][j][0]) {
    				upd(f[i+1][j+1][0], f[i][j][0]);
    				upd(f[i+1][j][0], f[i][j][0]*pw[j]%P);
    			}
    			if(f[i][j][1]) {
    				if(a[i+1]) upd(f[i+1][j+1][1], f[i][j][1]);
    				if(a[i+1]) upd(f[i+1][j][0], f[i][j][1]*(j?pw[j-1]:1)%P);
    				upd(f[i+1][j][1], f[i][j][1]*(j?pw[j-1]:0)%P);
    			}
    		}
    		ll ans=0;
    		rep(i,0,n+1) rep(j,0,2) if(f[n][i][j]) {
    			upd(ans, f[n][i][j]);
    		}
    		printf("%lld
    ",ans);
    	} 
    	return 0;
    }
    
  • 相关阅读:
    System.Web.Http.Cors配置跨域访问的两种方式
    asp.net反向代理
    web.config SetAttributes
    remove name="ProxyModule“会导致重复执行
    去空格
    api签名
    C# HttpWebRequest获取COOKIES
    Request.Form接收不到post数据.
    webapi文档工具
    https://gogs.io/
  • 原文地址:https://www.cnblogs.com/wuyuanyuan/p/8598194.html
Copyright © 2020-2023  润新知