2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest C Explode 'Em All

暴力枚举,状态压缩。

枚举哪几行放,复杂度为$O(2^{25})$,大概有$3000$多万种情况。假设有$x$行放了,没放的那几行状态或起来为$st$,如果$st$中$1$的个数大于$x$,那么不可取;否则用$x$更新答案。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} char s[][];
int n,m,ans,num[];
int f[]; void dfs(int x,int cnt,int st)
{
if(cnt>=ans) return ;
if(x==n)
{
if(f[st]<=cnt) ans=min(ans,cnt);
return ;
} dfs(x+,cnt+,st);
dfs(x+,cnt,st|num[x]);
} int lowbit(int x)
{
return x&(-x);
} int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); for(int i=;i<(<<);i++) f[i]=f[i-lowbit(i)]+; scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%s",s[i]);
for(int j=;j<m;j++)
if(s[i][j]=='*') num[i]=num[i]+(<<j);
} ans=min(n,m); dfs(,,);
printf("%d\n",ans);
return ;
}
上一篇:OpenSuSE zypper OpenStack Icehouse repoAdd


下一篇:最新-Linux常用命令大全-随时更新