首页 > 其他分享 >BZOJ 4800([Ceoi2015]Ice Hockey World Championship-meet in the middle)

BZOJ 4800([Ceoi2015]Ice Hockey World Championship-meet in the middle)

时间:2022-10-24 18:03:15浏览次数:48  
标签:4800 Championship return int ll Ceoi2015 long ch define


Description

有n个物品,m块钱,给定每个物品的价格,求买物品的方案数。
Input

第一行两个数n,m代表物品数量及钱数
第二行n个数,代表每个物品的价格
n<=40,m<=10^18
Output

一行一个数表示购买的方案数
(想怎么买就怎么买,当然不买也算一种)
Sample Input

5 1000

100 1500 500 500 1000
Sample Output

8
HINT

只有40个物品的0.1背包
我们双向广搜,然后排序合并。
复杂度O(2nlog(2n))=O(2n∗n)

#include<bits/stdc++.h> 
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
int n,cnt=0;
ll a[MAXN],v[MAXN];
ll m;
void dfs(int x,ll s,int n) {
if (s>m) return;
if (x==n+1) {
v[++cnt]=s;
return;
}
dfs(x+1,s+a[x],n);
dfs(x+1,s,n);

}
ll Ans=0;
void dfs2(int x,ll s,int n) {
if (s>m) return;
if (x==n+1) {
int l=1,r=cnt,ans=0;
while(l<=r) {
int mi=(l+r)/2;
if (s+v[mi]<=m) ans=mi,l=mi+1;else r=mi-1;
}
Ans+=ans;

return;
}
dfs2(x+1,s+a[x],n);
dfs2(x+1,s,n);

}

int main()
{
// freopen("bzoj4800.in","r",stdin);
// freopen(".out","w",stdout);
n=read();
cin>>m;
For(i,n) cin>>a[i];
int mid=n/2;
dfs(1,0,mid);
sort(v+1,v+1+cnt);
dfs2(mid+1,0,n);
cout<<Ans<<endl;

return 0;
}


标签:4800,Championship,return,int,ll,Ceoi2015,long,ch,define
From: https://blog.51cto.com/u_15724837/5790755

相关文章