摺紙,每次都是將紙從右向左對摺,凹痕爲 0,凸痕爲 1,求折 n
次的後,將紙展開所得摺痕組成的 01 序列。
代碼如下:
public class zhezhiHeng {
public static String s="";
public static void main(String[] args) {
// TODO Auto-generated method stub
findProccess(1,2,true);
System.out.println(s);
}
public static void findProccess(int i,int n,boolean down){
if(i>n) return ;
findProccess(i+1,n,true);
if(down) s+="0";
else s+="1";
findProccess(i+1,n,false);
}
}