/*http://acm.nyist.net/JudgeOnline/problem.php?pid=491*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class search_491 {
private static int n, count;
private static char tmp[];
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
while (sc.hasNext()) {
n = sc.nextInt();
count = 0;
find("+", n - 1, 1, 0);
find("-", n - 1, 0, 1);
System.out.println(count);
}
sc.close();
}
private static void find(String sb, int m, int acount, int bcount) {
// 获取到最顶层了,那就剩下n-1层
if (m == 0) {
tmp = sb.toCharArray();
// 获取到第一层的+-分别多少
int a = acount, b = bcount;
// 遍历n-1层
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (tmp[j] == tmp[j + 1]) {
tmp[j] = '+';
a++;
} else {
tmp[j] = '-';
b++;
}
}
}
if (a == b)
count++;
return;
}
find(sb + "+", m - 1, acount + 1, bcount);
find(sb + "-", m - 1, acount, bcount + 1);
}
}
NYOJ-491(搜索)-题目-----------------------------幸运三角形
最新推荐文章于 2017-03-29 22:48:55 发布