zoukankan      html  css  js  c++  java
  • BZOJ4800 [Ceoi2015]Ice Hockey World Championship

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

    本文作者:ljh2000
    作者博客:http://www.cnblogs.com/ljh2000-jump/
    转载请注明出处,侵权必究,保留最终解释权!


    题目链接:BZOJ4800

    正解:$meet$ $in$ $the$ $middle$

    解题报告:

      $meet$ $in$ $the$ $middle$一眼题==

      $40$就分成两半,分别做完之后,那一半到另一半去查找就好了。

    //It is made by ljh2000
    //有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <complex>
    #include <vector>
    #include <cstdio>
    #include <string>
    #include <bitset>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define lc root<<1
    #define rc root<<1|1
    #define pr pair<int,int>
    #define MP make_pair
    #define fr first
    #define sc second
    #define rep(i,j,k) for(int i=j;i<=k;++i)
    #define per(i,j,k) for(int i=j;i>=k;--i)
    #define reg(i,x) for(int i=first[x];i;i=next[i])
    using namespace std;
    typedef long long LL;
    typedef long double LB;
    typedef complex<double> C;
    const double pi = acos(-1);
    const double eps = 1e-9;
    const int MAXN = 2000011;
    int n,lim,cnt,l,r;
    LL m,ans,c[MAXN],a[45];
    
    inline LL getint(){
        LL w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
        if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
    }
    
    inline void dfs(int x,LL sum){
    	if(sum>m) return ;
    	if(x==lim+1) { c[++cnt]=sum; return ; }
    	dfs(x+1,sum+a[x]); dfs(x+1,sum);
    }
    
    inline void dfs2(int x,LL sum){
    	if(sum>m) return ; 
    	if(x==lim+1) {
    		if(c[1]+sum>m) return ;
    		l=1; r=cnt; int mid,pos=0;
    		while(l<=r) {
    			mid=(l+r)>>1;
    			if(sum+c[mid]<=m) pos=mid,l=mid+1;
    			else r=mid-1;
    		}
    		ans+=pos;
    		return ;
    	}
    	dfs2(x+1,sum+a[x]);
    	dfs2(x+1,sum);
    }
    
    inline void work(){
    	n=getint(); m=getint();
    	rep(i,1,n) a[i]=getint();
    	int mid=n>>1; 
    	lim=mid; dfs(1,0); 
    	sort(c+1,c+cnt+1);
    	lim=n; dfs2(mid+1,0);
    	printf("%lld",ans);
    }
    
    int main()
    {
    #ifndef ONLINE_JUDGE
    	freopen("4800.in","r",stdin);
    	freopen("4800.out","w",stdout);
    #endif
        work();
        return 0;
    }
    //有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
    

      

  • 相关阅读:
    动手学习TCP:TCP连接建立与终止
    动手学习TCP: 环境搭建
    Python 数据分析4
    Django unittest 单元测试
    Django commands自定制
    Python mac安装mysqlclient的一个bug
    Centos7 开机启动流程
    Centos 06 文件类型和扩展名&索引节点inode和存储块block
    Centos 05 系统目录讲解
    Linux 踩过的坑系列-01
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/6657347.html
Copyright © 2011-2022 走看看