《编程之美》 Problem4_10 数字哑谜和回文
2010-08-14 20:15
274 查看
Note: 是该节的问题1
//import java.io.*; import java.util.*; public class Problem4_10 { private int[] ret=new int[9]; private int retTop=0; public boolean DFS(boolean[] chosen,int depth,int number){ if(depth>0){ if(number%depth!=0)//pruning: return false; else if(depth==9)//final state return true; else; } for(int i=1;i<=9;i++) if(!chosen[i]){ chosen[i]=true; number=number*10+i; if(DFS(chosen,depth+1,number)){ ret[retTop++]=i; return true; }else{//restore chosen[i]=false; number=number/10; } } return false;//no way! } public void printOut(){ while(retTop>0){ System.out.printf("%d",ret[retTop-1]); retTop--; } System.out.println(); } public static void main(String[] args){ Problem4_10 test=new Problem4_10(); boolean[] chosen=new boolean[10]; Arrays.fill(chosen, false); test.DFS(chosen, 0, 0); test.printOut(); } }
相关文章推荐
- 编程之美:第四章 数字之趣 4.10_2数字哑谜和回文
- 《编程之美》4.10数字哑谜和回文
- 编程之美:第四章 数字之趣 4.10数字哑谜和回文
- 数字哑谜和回文游戏
- 数字哑谜和回文
- 编程之美——数字哑谜
- 读书笔记之编程之美 - 4.10 数字哑谜和回文
- 数字哑谜和回文
- 4.10 数字哑谜和回文
- 编程之美-数字哑谜和回文方法整理
- 数字哑谜和回文
- 编程之美 数字哑谜和回文小程序
- 编程之美——数字哑谜
- Accelerated C++ 课后习题5-10,回文查找
- 判断一个字符串是否是“回文”数字
- python数字图像处理(10):图像简单滤波
- 【历届试题】回文数字
- 【math】9.Palindrome Number 回文数字判断
- input 输入数字而且最大为10
- 游戏编程入门(10):播放数字声音效果