【bzoj4976】宝石镶嵌

题解:

比较水

注意k<=100这个条件

当n-k比较大的时候

我们显然会把它有的位都给取了

不然的话我们可以考虑dp

暴力状压就可以了

代码:

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
const int N=2e5;
int a[N];
bool t[];
vector<int> ve[];
bool f[][];
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k; k=n-k;
rep(i,,n) cin>>a[i];
if (k>=)
{
rep(i,,n)
dep(j,,) t[j]|=(a[i]>>j)&;
int ans=;
rep(i,,)
if (t[i]) ans+=<<i;
cout<<ans<<endl;
exit();
}
f[][]=;
rep(i,,k-)
rep(j,,(<<)-)
if (f[i][j])
rep(l,,n)
f[i+][j|a[l]]=;
dep(j,(<<)-,)
if (f[k][j])
{
cout<<j<<endl;
exit();
}
return ;
}
上一篇:FFmpeg——AVCodec,AVCodecContext,AVCodecParameters 辨析


下一篇:为autoLayout 增加标识符,方便调试