hdu 2510 符号三角形 回溯

2^n的回溯算法,n<=24,打表即可。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAX 25
//ashione 2012-4-19
//打表,不打表会超时,因为回溯算法的时间复杂度是很高的。注释掉的代码是打表的。
int q[MAX][MAX];
int readc[MAX]={0,0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757,59984,0,0,431095,822229};
/*
int sum,count;
void make(int t,int n){
         if(count>(n+1)*(n)/4 || (t-1)*t/2 - count>(n+1)*n/4)
                return ;
         if(t>n){
                 sum++;
//               cout<<"hello"<<endl;
                 return ;
         }
         for(int i=0;i<2;i++){
                 q[1][t] = i;
                 count+=i;
                 for(int j=2;j<=t;j++){
                                q[j][t-j+1] = q[j-1][t-j+1]^q[j-1][t-j+2];
                                count+=q[j][t-j+1];
                 }
                 make(t+1,n);
                 for(int j=1;j<=t;j++)
                         count-=q[j][t-j+1];
         }

}
*/
int main(){
        int n;
/*
        for(int i=1;i<=24;i++){
                count = sum= 0;
                memset(q,0,sizeof(q));
                if((i*(i+1)/2)%2 == 0)
                        make(1,i);
                        readc[i] =sum;
                cout<<readc[i]<<",";
        }
        cout<<endl;
*/
        while(cin>>n && n){
                cout<<n<<" "<<readc[n]<<endl;
        }
        return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值