符号三角形

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1246    Accepted Submission(s):
664

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
 
打表代码:
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int a[];
char res[][];
int sum;
bool count(int n)
{
int p1=,p2=;
int i,j;
for(i=;i<=n;i++)
{
if(res[][i]=='+') p1++;
else p2++;
}
for(int i=;i<n;i++)
for(j=;j<=n-i;j++)
{
res[i][j]=(res[i-][j]==res[i-][j+]?'+':'-');
if(res[i][j]=='+') p1++;
else p2++;
}
if(p1==p2)
return ;
return ;
}
void dfs(int n,int s)
{
int i,j;
if(s>n)
{
if(count(n))
sum++;
return;
}
res[][s]='+';
dfs(n,s+);
res[][s]='-';
dfs(n,s+);
return;
}
int main()
{
int n;
int i,j;
a[]=a[]=;
for(i=;i<=;i++)
{
sum=;
dfs(i,);
a[i]=sum;
cout<<a[i]<<endl;
}
}

符号三角形(hdu 2510 搜索+打表)的更多相关文章

  1. hdu 2510 符号三角形 (DFS+打表)

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

  2. 符号三角形_hdu_2510(深搜).java

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

  3. 符号三角形——F

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

  4. code vs 3376 符号三角形

    3376 符号三角形  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 如下图是由14个“+”和14个“-”组 ...

  5. OpenJudge 2990:符号三角形 解析报告

    2990:符号三角形 总时间限制:  1000ms       内存限制:  65536kB 描述 符号三角形的第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“ ...

  6. hdu 1496 Equations hash表

    hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...

  7. hdu 5887 搜索+剪枝

    Herbs Gathering Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  9. 【a502】符号三角形问题

    Time Limit: 1 second Memory Limit: 32 MB [问题描述] 在一般情况下,符号三角形的第一行有n个符号.按照2个同号的下面是"+"号,2个异号的 ...

随机推荐

  1. 黑马程序员——读取Plist文件

    -iOS培训,iOS学习-------型技术博客.期待与您交流!------------ 读取Plist文件     一:新建一个plist文件,并将plist文件数据填入plist文件中,这里pli ...

  2. .NET抽象工厂模式微理解--教你在项目中实现抽象工厂

    .NET抽象工厂模式微理解--教你在项目中实现抽象工厂 最近在学习MVC,对于MVC里面的一些项目上的东西都和抽象模式有关,今天就微说明一下个人对于抽象工厂模式的理解,以方便学习MVC及工厂模式相关的 ...

  3. android 显示特殊符号

    http://hsx9566.iteye.com/blog/1305052 在android上使用ASCII显示特殊符号 在xml中表示如下: <string name="symbol ...

  4. Spring-AOP实践 - 统计访问时间--StopWatch

    公司的项目有的页面超级慢,20s以上,不知道用户会不会疯掉,于是老大说这个页面要性能优化.于是,首先就要搞清楚究竟是哪一步耗时太多. 我采用spring aop来统计各个阶段的用时,其中计时器工具为S ...

  5. 107个常用Javascript语句

    1.document.write( " "); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document- >html- >(head,body ...

  6. Swap Nodes in Pairs 解答

    Question Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1 ...

  7. 《Two Days DIV + CSS》读书笔记——CSS选择器

    1.1.2 CSS选择器 CSS 选择器最基本的有四种:标签选择器.ID 选择器.类选择器.通用选择器. [标签选择器] 一个完整的 HTML 页面由很多不同的标签组成,而标签选择器,则是决定哪些标签 ...

  8. WifiDog系统

    WifiDog:A captive portal suite What is it composed of ? A: It is composed of 2 components: The clien ...

  9. Java I/O 模型的演进

    什么是同步?什么是异步?阻塞和非阻塞又有什么区别?本文先从 Unix 的 I/O 模型讲起,介绍了5种常见的 I/O 模型.而后再引出 Java 的 I/O 模型的演进过程,并用实例说明如何选择合适的 ...

  10. [置顶] 正则表达式应用:匹配IP地址

    都知道iP地址有四个数值,三个点号组成.三个数值的具体范围为0到255,为了使用正则表达式匹配就必须分析IP地址的组成 1先分析数值,2再组合数值和点号 1先分析数值 IP地址的数字范围从0到255, ...