zoukankan      html  css  js  c++  java
  • fzu 2107 Hua Rong Dao(状态压缩)

    Problem 2107 Hua Rong Dao

    Accept: 106    Submit: 197
    Time Limit: 1000 mSec    Memory Limit : 32768 KB

     Problem Description

    Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.

    There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?

     Input

    There is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.

    Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.

     Output

    For each test case, print the number of ways all the people can stand in a single line.

     Sample Input

    212

     Sample Output

    018

     Hint

    Here are 2 possible ways for the Hua Rong Dao 2*4.

     Source

    “高教社杯”第三届福建省大学生程序设计竞赛
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    const int N=(1<<4);
    int f[6][N][2]={0};//f[i][j][k]//放完第i-1行第i行的状态j,k=1放曹操
    void dfs(int row,int col,int pre,int now,int cao,int k){
    	if(col>=4){//放完4列,pre={1111}
    		f[row][now][cao]+=k;//放完pre得到f[now]+=f[pre]
    		//cout<<row<<" "<<now<<" "<<cao<<endl;
    		return;
    	}
    	if(pre&(1<<col)){//第col已经放过
    		dfs(row,col+1,pre,now,cao,k);
    		return;
    	}
    	//a grid
    	dfs(row,col+1,pre|(1<<col),now,cao,k);
    	//a 1*2
    	dfs(row,col+1,pre|(1<<col),now|(1<<col),cao,k);//放一竖,多出一块
    	int t=(1<<col)|(1<<(col+1));
    	if(col<3&&(pre&(1<<(col+1)))==0){
    		//a 2*1
    		dfs(row,col+1,pre|t,now,cao,k);
    		//put caocao
    		if(cao==0)dfs(row,col+1,pre|t,now|t,1,k);
    	}
    }
    int main(){
    	int i,j,k;
    	f[0][N-1][0]=1;
    	for(i=1;i<=5;i++)
    		for(j=0;j<N;j++){
    			if(f[i-1][j][0])dfs(i,0,j,0,0,f[i-1][j][0]);
    			if(f[i-1][j][1])dfs(i,0,j,0,1,f[i-1][j][1]);
    		}
    	scanf("%d",&k);
    	while(k--){
    		scanf("%d",&i);
    		printf("%d
    ",f[i+1][0][1]);
    	}
    return 0;
    }


  • 相关阅读:
    Java深度历险(四)——Java垃圾回收机制与引用类型
    Java深度历险(三)——Java线程​:基本概念、可见性与同步
    Java深度历险(一)——Java字节代码的操纵(转)
    SVN问题:Cleanup failed to process the following paths: xxxxxx
    解决 ORA-12154: TNS:could not resolve service name
    Linq 实现普通sql中 where in 的功能
    C# 操作电脑 关机 重启 注销 休止 休眠
    使用C#代码追加和提交文件到SVN服务器
    access 2007 vba (亖)
    access 2007 vba 开发中学到的知识(三)
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3249288.html
Copyright © 2011-2022 走看看