fork download
  1. public class Main {
  2.  
  3. static int stack[] = new int[100],
  4. n,
  5. level;
  6.  
  7. public static void init() {
  8. stack[level] = -1;
  9. }
  10.  
  11. public static boolean valid() {return true;}
  12.  
  13. public static boolean succ() {
  14.  
  15. if(stack[level]<1){
  16. stack[level]++;
  17. return true;
  18. }
  19. return false;
  20. }
  21.  
  22. public static boolean sol() {
  23. return (level == n);
  24. }
  25.  
  26. public static void main(String args[]) {
  27. n = 3;
  28. bk();
  29. }
  30.  
  31. public static void bk() {
  32. level = 1;
  33. boolean s,v;
  34. init();
  35. while(level>0){
  36. s = true;
  37. v = false;
  38. while(s && !v){
  39. s = succ();
  40. if(s) v = valid();
  41. }
  42. if(s) {
  43. if(sol())print();
  44. else{
  45. level++;init();
  46. }
  47. }else{
  48. level--;
  49. }
  50. }
  51. }
  52.  
  53. public static void print() {
  54.  
  55. for(int i = 1; i <= n; ++i){
  56. if(stack[i] == 1) {
  57. System.out.print(i + " ");
  58. }
  59. }
  60. System.out.println("\n");
  61. }
  62. }
  63.  
Success #stdin #stdout 0.09s 55608KB
stdin
Standard input is empty
stdout

3 

2 

2 3 

1 

1 3 

1 2 

1 2 3