http://115.28.138.223:81/view.page?opid=4
这道题写的我醉醉的,想建一棵指定深度的树最后统计满足条件的个数
居然没去考虑这样必然超时!!!代码写的也是醉了,把没完成的代码先贴出来,好好嘲讽下自己
(╬▔皿▔)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int floorer,num,lable;//0 none ; 1 1 ; 3 3 ; 4 1&3 bool shine1,shine0,shine3,shit,shit0; int x[]={0,2,1,3}; int y[]={2,0,1,3}; int donser1=0,donser2=0,donser3=0,donser4=0,donser5=0; bool dong1=false,dong2=false,dong3=false,dong4=false,dong5=false; void creatree(int lab,int flooor) { cout<<"-------->floor:"<<flooor<<"(12)"<<endl; if((flooor==floorer+1)&&shine0&&shine1&&shine3){cout<<"*********************************************";num++;} if(flooor==floorer+1){cout<<endl<<"&return "<<endl<<endl;return;} if(shit&&shit0) { for(int i=1;i<3;i++) { cout<<"lab -1 : "<<y[i]<<"(19)"<<endl; if(y[i]==0){dong1=shine0;shine0=1;donser1=1;} if(y[i]==1){dong1=shine1;shine1=1;lab=1;donser1=2;} if(y[i]==3){dong1=shine3;shine3=1;lab=3;donser1=3;} if(flooor==floorer+1){cout<<"++++"<<"(23)"<<endl;return;} int ii=flooor; creatree(lab,++ii); if(donser1==1){shine0=dong1;donser1=0;} if(donser1==2){shine1=dong1;donser1=0;} if(donser1==3){shine3=dong1;donser1=0;} } } if(lab==0) { for(int i=0;i<4;i++) { cout<<"lab 0 : "<<x[i]<<"(31)"<<endl; if(y[i]==0){dong2=shine0;shine0=1;donser2=1;} if(y[i]==1){dong2=shine1;shine1=1;lab=1;donser2=2;} if(y[i]==3){dong2=shine3;shine3=1;lab=3;donser2=3;} if(flooor==floorer+1){cout<<"????"<<"(35)"<<endl;return;} int ii=flooor; creatree(lab,++ii); if(donser2==1){shine0=dong2;donser2=0;} if(donser2==2){shine1=dong2;donser2=0;} if(donser2==3){shine3=dong2;donser2=0;} } } if(lab==1) { for(int i=1;i<4;i++) { cout<<"lab 1 : "<<x[i]<<"(43)"<<endl; if(x[i]==3){dong3=shine3;shine3=1;lab=4;shit=false;donser3=1;} if(flooor==floorer+1){cout<<"...."<<"(45)"<<endl;return;} int ii=flooor; creatree(lab,++ii); if(donser3==1){shine3=dong3;donser3=0;} } } if(lab==3) { for(int i=1;i<4;i++) { cout<<"lab 3 : "<<y[i]<<"(43)"<<endl; if(!y[i]==1&&!shine1){shit=true;} if(y[i]==1) {shit=false;dong4=shine1;shine1=1;lab=4;donser4=1;} if(flooor==floorer+1){cout<<"````"<<"(56)"<<endl;return;} int ii=flooor; creatree(lab,++ii); if(donser4==1){shine1=dong4;donser4=0;} } } if(lab==4) { for(int i=2;i<4;i++) { cout<<"lab 4 : "<<y[i]<<"(64)"<<endl; if(flooor==floorer+1){cout<<"----"<<"(65)"<<endl;return;} int ii=flooor; creatree(lab,++ii); } } } int main() { int n,flooor; while(cin>>n) { floorer=n; shine1=shine0=shine3=shit=shit0=false; num=lable=0; flooor=2; creatree(0,flooor); cout<<num<<endl; cout<<endl<<endl; cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"; shine1=shine0=shine3=shit=false; shit0=true; creatree(3,flooor); cout<<num<<endl; cout<<endl<<endl; cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++"; shine1=shine0=shine3=shit=false; shit0=true; creatree(0,flooor); cout<<num<<endl; } return 0; }
#include<iostream> using namespace std; int main() { long long mod=1000000007; long long n; cin>>n; long long**donser=new long long*[n+1]; for(long long i=0; i<n+1; i++) donser[i]=new long long[6]; for(long long i=0; i<6; i++) donser[0][i]=0; /*6种状态 *0--剩013 *1--剩13 *2--剩01 *3--剩3 *4--剩1 *5--无 */ for(long long i=1; i<=n; i++) { long long j=i-1; donser[i][0]=1; donser[i][1]=(donser[j][0]+donser[j][1]*2)%mod; donser[i][2]=(donser[j][0]+donser[j][2])%mod; donser[i][3]=(donser[j][1]+donser[j][3]*2)%mod; donser[i][4]=(donser[j][1]+donser[j][2]+donser[j][4]*2)%mod; donser[i][5]=(donser[j][3]+donser[j][4]+donser[j][5]*2)%mod; } cout<<donser[n][5]<<endl; return 0; }