符号三角形

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. IOS 文件管理 2

    IOS开发-文件管理(二) 五.Plist文件 String方式添加               NSString *path = [NSHomeDirectory( )  stringByAppen ...

  2. Android开发之打开闪光灯录制视频

    Android的SDK在线API上对录制视频的方法.步骤都写得非常清楚,但是如果没有一点思路,写起来也比较式费事.录制视频的全过程要打开闪光灯(可能是因为项目需要,或者特殊原因),则必须按照一定的顺序 ...

  3. CC2530 PWM波形产生。

    1.使用TIM3_CC1,相关联引脚P1_7 #define GPIOPWM() do{P1SEL |= 0x80;}while(0);#define GPIOCLOSEPWM() do{P1SEL  ...

  4. Netbeans使用Xdebug调试的配置

    在phpinfo()信息里找到php.ini的位置并打开php.ini在文档最后添加如下代码: 注释原来xdebug配置 xdebug.remote_enable=onxdebug.remote_ha ...

  5. bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛

    Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stal ...

  6. 清除IE输入框眼睛和叉叉

    /* 清除IE输入框眼睛和叉叉 */::-ms-clear { display: none; } ::-ms-reveal { display: none; }

  7. Merlin 的魔力: SpringLayout 管理器

    摘自http://tech.it168.com/a2009/0211/265/000000265087_all.shtml 摘自http://cache.baiducontent.com/c?m=9f ...

  8. jQuery autocomplete 使用

    推荐 :http://www.cnblogs.com/Peter-Zhang/archive/2011/10/22/2221147.html eg: $("#txtGrand"). ...

  9. PHP <<EOF EOF的使用方法

    PHP <<EOF EOF的使用方法 <?php     $name = '浅水游';     print <<<EOT             <html& ...

  10. android——仿网易今日头条等自定义频道listview 或者grideview等item上移到另一个view中

    转载请注明出处: www.cnblogs.com/shoneworn 我这里只是简单的用了两个listview来实现的,先上效果图.比较粗糙.预留了自定义的空间. 思路: 从上图应该可以看的出来.就是 ...