摺紙問題

摺紙,每次都是將紙從右向左對摺,凹痕爲 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);
}
}

發佈了28 篇原創文章 · 獲贊 13 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章