符号三角形

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. BufferedInputStream实现原理分析

    原文地址:http://blog.sina.com.cn/s/blog_67f995260101huxz.html BufferedInputStream是一个带有缓冲区的输入流,通常使用它可以提高我 ...

  2. memcached在Windows下的安装

    memcached简介详情请谷歌.这里介绍如何在windows下安装. 1.下载     下载地址:http://download.csdn.net/detail/u010562988/9456109 ...

  3. hdu 2473 Junk-Mail Filter

    http://acm.hdu.edu.cn/showproblem.php?pid=2473 并查集设置虚拟父节点. #include <cstdio> #include <cstr ...

  4. 单路CPU性能排名 更新于2015.10.6

    http://itianti.sinaapp.com/index.php/cpu 排名 处理器 图例 分数 1 Intel Xeon E5-2699 v3 @ 2.30GHz 22892 2 Inte ...

  5. 深入浅出Node.js (3) - 异步I/O

    3.1 为什么要异步I/O 3.1.1 用户体验 3.1.2 资源分配 3.2 异步I/O实现现状 3.2.1 异步I/O与非阻塞I/O 3.2.2 理想的非阻塞异步I/O 3.2.3 现实的异步I/ ...

  6. MVC View返回list列表

    );             Sql sql2 = );             Sql sql3 = );             Sql sql4 = );             Sql sql ...

  7. UVa 1449 - Dominating Patterns (AC自动机)

    题目大意:给出多个字符串模板,并给出一个文本串,求在文本串中出现最多的模板,输出最多的次数并输出该模板(若有多个满足,则按输入顺序输出). 思路:赤裸裸的 AC自动机,上模板. 代码: #includ ...

  8. JSTL解析——007——fmt标签库02

    各位亲们,近期事情比较多,没更新,come on! 1.<fmt:bundle>/<fmt:message>/<fmt:param>资源国际化标签 java中使用R ...

  9. AsyncTask实现下载图片

    实现效果: /*采用异步任务  AsyncTask<String,Integer, byte[]>  * 参数一代表 执行异步任务时传递的参数的类型  * 参数二 如果不采用进度,则填Vo ...

  10. 利用ant进行编译和发布项目

    本文通过一个示例来解说如何通过ant进行编译和发布项目.本例按如下目录结构来组织项目. D:/web/antsample项目根目录 D:/web/antsample/src源代码目录 D:/web/a ...