• BZOJ 1725: [Usaco2006 Nov]Corn Fields牧场的安排


    状压DP

    #include<cstdio>
    using namespace std;
    const int mod=1e8;
    int n,m,a[15][15],F[15][10005];
    void memse(int x){
    	for (int i=0; i<(1<<m); i++)
    		if (F[x][i]){
    			for (int j=0; j<m; j++)	if (!a[x][j] && i&(1<<j)) F[x][i]=0;
    		}
    }
    int main(){
    	scanf("%d%d",&n,&m);
    	for (int i=0; i<n;	i++)
    		for (int j=0; j<m; j++)
    			scanf("%d",&a[i][j]);
    	for (int i=0; i<(1<<m); i++) if (!(i&(i>>1))) F[0][i]=1;
    	for (int i=0; i<n; i++){
    		memse(i);
    		for (int pre=0; pre<(1<<m); pre++)
    			if (F[i][pre])
    				for (int now=0; now<(1<<m); now++)
    					if (!(now&(now>>1)) && !(now&pre)) (F[i+1][now]+=F[i][pre])%=mod;
    	}
    	int ans=0;
    	for (int i=0; i<(1<<m); i++) (ans+=F[n-1][i])%=mod;
    	printf("%d
    ",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    body test
    menu
    Toolbutton test itk_component
    grid pack
    double inherit
    set font
    Activity test itk_component
    Activity test no class
    按键驱动调试总结
    system.img解包打包的方法
  • 原文地址:https://www.cnblogs.com/silenty/p/9869089.html
Copyright © 2020-2023  润新知