[Ceoi2015]Ice Hockey World Championship
Posted lcxer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Ceoi2015]Ice Hockey World Championship相关的知识,希望对你有一定的参考价值。
有n个物品,m块钱,给定每个物品的价格,求买物品的方案数。
n<=40,m<=10^18
水题,meet in the middle裸题,随便搞搞,统计答案二分一下就没了
#include<cstdio>
#include<algorithm>
int n,sum;long long m,f[1500001],a[41],ans;
void dfs(int x,long long now){
if(x>n/2){f[++sum]=now;return ;}
dfs(x+1,now),dfs(x+1,now+a[x]);}
void dfs1(int x,long long now){
if(x>n){ans+=(std::upper_bound(f+1,f+sum+1,m-now)-f)-1;return ;}
dfs1(x+1,now),dfs1(x+1,now+a[x]);}
int main(){
scanf("%d%lld",&n,&m);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
dfs(1,0);std::sort(f+1,f+sum+1);dfs1(n/2+1,0);
printf("%lld
",ans);}
以上是关于[Ceoi2015]Ice Hockey World Championship的主要内容,如果未能解决你的问题,请参考以下文章
BZOJ4800 [Ceoi2015]Ice Hockey World Championship
bzoj4800: [Ceoi2015]Ice Hockey World Championship dfs
[bzoj4800][Ceoi2015]Ice Hockey World Championship
bzoj4800[Ceoi2015]Ice Hockey World Championship 折半搜索