Last active
December 19, 2015 17:18
-
-
Save pocari/5989685 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Haisen { | |
private static final int ROW = 3; | |
private static final int COL = 5; | |
private static void printAnswer(List<Integer> cols) { | |
for (Integer i : cols) { | |
System.out.print(i + " "); | |
} | |
for (int i = 0; i < COL - cols.size(); i++) { | |
System.out.print("0 "); | |
} | |
System.out.println(); | |
printPattern(cols); | |
} | |
private static void search(List<Integer> cols, int num) { | |
if (num == 0) { | |
printAnswer(cols); | |
} else { | |
for (int i = 1; i <= ROW; i++) { | |
if ((cols.size() < COL) && (num - i >= 0)) { | |
List<Integer> added = new ArrayList<Integer>(cols); | |
added.add(i); | |
search(added, num - i); | |
} | |
} | |
} | |
} | |
private static void printPattern(List<Integer> pattern) { | |
for (int r = 0; r < ROW; r++) { | |
for (int c = 0; c < COL; c++) { | |
if (pattern.size() <= c) { | |
System.out.print("□"); | |
} else if (r < pattern.get(c)) { | |
System.out.print("■"); | |
} else { | |
System.out.print("□"); | |
} | |
} | |
System.out.println(""); | |
} | |
System.out.println(""); | |
} | |
public static void main(String[] args) { | |
for (int i = 1; i <= ROW * COL; i++) { | |
System.out.println(i + "個塗るパターン------------------------------"); | |
search(new ArrayList<Integer>(), i); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment