n只有24 可以写个暴力搜索,然后打表,不然这个很难通过剪枝直接优化到1s以内。
#include<bits/stdc++.h> #define inf 0x3f3f3f3f const int maxn=; using namespace std; int n,m,ans; int res[maxn+]={,,,,,,,,,,,,,,,,,,,,,,,,}; int a[maxn+][maxn+]; void dfs(int layer,int lnum,int pos,int nei,int n){
//printf("%d %d %d %d\n",layer,lnum,pos,nei);
if(pos+nei>m) return ;
if(pos-nei>(m-pos-nei)) {
//printf("%d %d\n",pos,nei);
return ;
}
if(layer==&&pos==m/&&nei==m/){
ans++;
return ;
}
if(layer==&&(pos!=m/||nei!=m/)) return ;
if(pos>m/||nei>m/) return ;
if(layer==n&&lnum<=layer){
a[layer][lnum]=;
if(lnum==layer)
dfs(layer-,,pos+,nei,n);
else dfs(layer,lnum+,pos+,nei,n);
a[layer][lnum]=-;
if(lnum==layer)
dfs(layer-,,pos,nei+,n);
else dfs(layer,lnum+,pos,nei+,n);
} else if(layer!=n){
if(lnum<=layer){
if(a[layer+][lnum]==a[layer+][lnum+]){
a[layer][lnum]=;
if(lnum==layer)
dfs(layer-,,pos+,nei,n);
else dfs(layer,lnum+,pos+,nei,n);
} else {
a[layer][lnum]=-;
if(lnum==layer)
dfs(layer-,,pos,nei+,n);
else dfs(layer,lnum+,pos,nei+,n); }
} }
} int main()
{
/*for(int i=1;i<=24;i++){
m=(i*(i+1)/2);
if(m&1){
printf("0\n");
} else {
ans=0;
dfs(i,1,0,0,i);
printf("%d\n",ans);
}
}*/
while(scanf("%d",&n)!=EOF&&n){
printf("%d %d\n",n,res[n]);
}
return ;
}