• jzoj5991. 【北大2019冬令营模拟2019.1.6】Juice


    题面

    题解

    好迷……

    //minamoto
    #include<bits/stdc++.h>
    #define R register
    #define ll long long
    #define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
    #define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
    #define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
    template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
    using namespace std;
    char buf[1<<21],*p1=buf,*p2=buf;
    inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
    int read(){
        R int res,f=1;R char ch;
        while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
        for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
        return res*f;
    }
    char sr[1<<21],z[20];int C=-1,Z=0;
    inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
    void print(R int x){
        if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
        while(z[++Z]=x%10+48,x/=10);
        while(sr[++C]=z[Z],--Z);sr[++C]='
    ';
    }
    const int N=(1<<20)+5;
    int a[25],sz[N],n,lim,ans;ll sum,s[N],b[N];
    bool ck(int m){
    	fp(i,1,n)b[i]=1ll*m*a[i]-sum;
    	fp(S,1,lim-1){
    		s[S]=0;
    		fp(i,0,n-1)if(S&(1<<i))s[S]+=b[i+1];
    	}
    	int S=lim-1;
    	fp(i,1,n)if(b[i]==0)S^=1<<(i-1);
    	while(true){
    		int flag=1;
    		for(R int i=S;i;i=(i-1)&S)if(s[i]==-sum){
    			S^=i,flag=0;break;
    		}if(flag)return false;
    		if(!S)break;
    	}return true;
    }
    int main(){
    //	freopen("testdata.in","r",stdin);
    	freopen("juice.in","r",stdin);
    	freopen("juice.out","w",stdout);
    	n=read(),lim=(1<<n);
    	fp(i,1,n)a[i]=read(),sum+=a[i];
    	fp(i,1,n)if(ck(i))return printf("%d
    ",i),0;
    	return 0;
    }
    
  • 相关阅读:
    UVA 1025 A Spy in the Metro DP水题
    ZOJ 3814 Sawtooth Puzzle BFS
    ZOJ 3816 Generalized Palindromic Number
    UVA 10859 Placing Lampposts 树形DP
    UVA 11825 Hackers' Crackdown 状压DP
    POJ 2887 Big String 线段树 离线处理
    POJ 1635 Subway tree systems Hash法判断有根树是否同构
    BZOJ 3110 k大数查询 & 树套树
    sdoi 2009 & 状态压缩
    来自于2016.2.24的flag
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/10230309.html
Copyright © 2020-2023  润新知