#include<string.h>
#include <stdio.h>
![](/Images/OutliningIndicators/None.gif)
int m, n;
__int64 f[12][2048];
__int64 g[12][12];
![](/Images/OutliningIndicators/None.gif)
void DFS(int i, int j, int j2, int m2)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
if(m2 == m)
f[i+1][j2]+=f[i][j];
else if((j2&(1<<m2))==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
DFS(i,j,j2 | (1<<m2),m2+1);
if(m2<m-1 && (j2&(1<<(m2+1)))==0)DFS(i,j,j2,m2+2);
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
DFS(i,j,j2&~(1<<m2),m2+1);
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
int main()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(m=1;m<=11;m++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
![](/Images/OutliningIndicators/InBlock.gif)
int i, j;
memset(f,0,sizeof(f));
f[0][0]=1;
for (i=0; i<11; i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for (j=0; j<(1<<m); j++)
if(f[i][j])
DFS(i,j,j,0);
![](/Images/OutliningIndicators/InBlock.gif)
g[i+1][m]=f[i+1][0];
}
// printf("(%d,%d)=%I64d \n",n,m,g[n][m]);
}
// printf("\n");
}
while(scanf("%d%d",&n,&m)==2)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(m==0 && n==0)break;
printf("%I64d\n",g[n][m]);
}
return 0;
}
|
|
|