fzu 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
Sample Input
Sample Output
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\n",f[i+1][0][1]); } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)