http://acm.hdu.edu.cn/showproblem.php?pid=2510
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 729    Accepted Submission(s): 361

Problem Description

符号三角形的 第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“,2个异 号下面是”-“ 。计算有多少个不同的符号三角形,使其所含”+“ 和”-“ 的个数相同 。 n=7时的1个符号三角形如下:

+ + - + - + + 

+ - - - - + 

- + + + - 

- + + - 

- + - 

- - 

+

Input

每行1个正整数n <=24,n=0退出.

Output

n和符号三角形的个数.

Sample Input

15

16

19

20

0

Sample Output

15 1896

16 5160

19 32757

20 59984

import java.util.Scanner;

public class Main{//打表AC
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int a[]={0,0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757,59984,0,0,431095,822229};
while(true){
int n=input.nextInt();
if(n==0)
break;
System.out.println(n+" "+a[n]);
}
}
}
import java.util.Scanner;

public class Main{//深搜超时
static int n,sum;
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while((n=input.nextInt())!=0){
sum=0;
String b=new String("");
dfs(0,b);
System.out.println(n+" "+sum);
}
}
private static void dfs(int id, String b) {
if(id==n){
// System.out.println(b);
jc(b);
return;
}
dfs(id+1,b+"+");
dfs(id+1,b+"-");
}
private static void jc(String str) {
char s[]=str.toCharArray();
long a1=0,a2=0;
for(int i=0;i<s.length;i++){
if(s[i]=='+')a1++;
else a2++;
}
for(int i=1;i<=n-1;i++){
for(int j=1;j<=n-i;j++){
if(s[j-1]==s[j]){
a1++;
s[j-1]='+';
}
else{
a2++;
s[j-1]='-';
}
}
}
if(a1==a2){
//System.out.println("&&&&"+str);
sum++;
}
}
}
*import java.util.Scanner;

public class Main{//打表
static int n,sum;
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
for(n=1;n<25;n++){
sum=0;
String b=new String("");
dfs(0,b);
System.out.print(sum+",");
}
}
private static void dfs(int id, String b) {
if(id==n){
// System.out.println(b);
jc(b);
return;
}
dfs(id+1,b+"+");
dfs(id+1,b+"-");
}
private static void jc(String str) {
char s[]=str.toCharArray();
long a1=0,a2=0;
for(int i=0;i<s.length;i++){
if(s[i]=='+')a1++;
else a2++;
}
for(int i=1;i<=n-1;i++){
for(int j=1;j<=n-i;j++){
if(s[j-1]==s[j]){
a1++;
s[j-1]='+';
}
else{
a2++;
s[j-1]='-';
}
}
}
if(a1==a2){
//System.out.println("&&&&"+str);
sum++;
}
}
}

符号三角形_hdu_2510(深搜).java的更多相关文章

  1. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  2. 符号三角形——F

    F. 符号三角形 Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format:      Java class name: 符号 ...

  3. 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目

    [题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  4. HDOJ/HDU 1015 Safecracker(深搜)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  5. ZOJ(ZJU) 1002 Fire Net(深搜)

    Suppose that we have a square city with straight streets. A map of a city is a square board with n r ...

  6. 符号三角形(hdu 2510 搜索+打表)

    符号三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. Hidden String(深搜)

    Hidden String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  8. HDU1342 Lotto 【深搜】

    Lotto Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  9. ****Curling 2.0(深搜+回溯)

    Curling 2.0 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total ...

随机推荐

  1. openstack vm实例pxe无法启动

    问题如下: 创建vm没有任何报错,打开控制台提示: SeaBIOS (versio xxxxxxx) Machine UUID xxxxxxxxxx iPXE (http://ipxe.org) 00 ...

  2. [BZOJ5093]图的价值(NTT+第二类Stirling数)

    5093: [Lydsy1711月赛]图的价值 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 250  Solved: 130[Submit][Sta ...

  3. HDU1429 胜利大逃亡 状压bfs

    http://acm.hdu.edu.cn/viewcode.php?rid=22225154 因为总共a-j有10种钥匙,所以可以把有没有钥匙的状态压到一个int数里,然后dfs. 昨天状态特别不好 ...

  4. [CodeForces-440D]Berland Federalization

    题目大意: 给你一棵树,你可以删掉一些边,使得分除去的子树中至少有一棵大小为k. 问最少删去多少边,以及删边的具体方案. 思路: 树形DP. f[i][j]表示以i为根,子树中去掉j个点最少要删边的数 ...

  5. 矩阵乘法快速幂 cojs 1717. 数学序列

    矩阵乘法模板: #define N 801 #include<iostream> using namespace std; #include<cstdio> int a[N][ ...

  6. nginx 访问第三方服务(1)

    nginx提供了两种全异步方式来与第三方服务通信,分别是upstream和subrequest. upstream:nginx为代理服务器,作消息透传.将第三方服务的内容原封不动的返回给用户. sub ...

  7. SCOJ 4427: Miss Zhao's Graph dp

    4427: Miss Zhao's Graph 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4427 Description Mr Jiang ...

  8. Linux可以明文传输密码的工具sshpass

    普通ssh只能手动输入密码,但是sshpass可以明文指定密码,但不建议使用,太不安全了.

  9. dubbo知识点理解2

    作者:网易云链接:https://www.zhihu.com/question/45413135/answer/226794957来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  10. JSON还原为结构体

    JSON还原为结构体 1)JSON字符串还原为结构体: 2)访问结构体的字段值: 本例运行效果图: uses SynCommons; const // JSON字符串 JSON1 = '{' + #1 ...