F. 符号三角形

Time Limit: 1000ms
Memory Limit: 32768KB

64-bit integer IO format:      Java class name:

符号三角形的 第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 开始 直接搜索都超时了,最后是搜索打表才ac的。 开始的搜索代码:
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=;
int n,a[N][N],c,h,sum;
int js_1(int k,int s)
{
for(int i=,j=k;i<k;i++,j--)
{
s+=a[i][j];
if(a[i][j-]==a[i][j])
a[i+][j-]=;
else
a[i+][j-]=;
}
return s;
}
void dfs(int t,int js)
{
if(t>n)
{
c++;
}
else
{
for(int i=;i<;i++)
{
a[][t]=i;
int x=js_1(t,js);
if(x<=h&&(t*(t+))/-x<=h)
dfs(t+,x);
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
c=;
sum=n*(n+)/;
if(sum%==)
{
h=sum/;
dfs(,);
}
printf("%d %d\n",n,c);
}
}

AC的代码:

#include <iostream>
using namespace std;
int result[]={,,,,,,,,,,,,,,,,,,,,,,,};
int main()
{
int n;
cin>>n;
while(n!=)
{
cout<<n<<" "<<result[n-]<<endl;
cin>>n;
}
return ;
}
 

符号三角形——F的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. code vs 3376 符号三角形

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

  7. 【HDOJ】2510 符号三角形

    暴力打表. #include <cstdio> ]={,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { while (scanf("%d" ...

  8. HDU 2510 - 符号三角形

    DFS后打表 #include <iostream> using namespace std; ,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { int n; ...

  9. 使用F#来实现哈夫曼编码吧

    最近算法课要求实现哈夫曼编码,由于前面的问题都是使用了F#来解决,偶然换成C#也十分古怪,报告也不好看,风格差太多.一开始是打算把C#版本的哈夫曼编码换用F#来写,结果写到一半就觉得日了狗了...毕竟 ...

随机推荐

  1. js判断手机端Android手机还是iPhone手机

    /*判断当前设备是平板.安卓.苹果设备*/ <script type="text/javascript"> function fBrowserRedirect(){ v ...

  2. gnuplot安装问题(set terminal "unknown")

    今天在系统同上要装个gnuplot,原来用的都是拷好的虚拟机.这也是第一次装.本来以为分分钟的事,却不料遇到不少麻烦.记录一下,供大家参考 一,快速开始安装 ubuntu下那自然是: sudo apt ...

  3. [SQL]查询及删除重复记录的SQL语句

    一:查询及删除重复记录的SQL语句1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select ...

  4. 提升 LaTeX 效率的小工具:Detexify LaTeX handwritten symbol recognition

    Detexify LaTeX handwritten symbol recognition 用 LaTeX 的人找符号的表示方法通常很费事,需要去翻长长的列表.Detexify 是一个省事的小网站,只 ...

  5. 【jQuery 分页】jQuery分页功能的实现

    自写的jQuery实现分页功能的分页组件: 功能效果如下: 分页组件就是上图中的三部分, 分别放在表格上部  和下部 . 其中, 1>>>页面的代码如下: product.jsp 其 ...

  6. java gui 之容器组件

    演示Frame和Panel package unit7; import java.awt.*; public class SimpleFrame { public static void main(S ...

  7. Android拓展系列(10)--使用Android Studio阅读整个Android源码

    之前一直在windows下用source insight阅读android源码,效果非常好.后来远程异地服务器,网络限制,一直用ssh + vim,现在主要还是以这种方式.最近发现一个不错的东西(早就 ...

  8. 基线 css

    原文地址:http://blog.jobbole.com/31926/ 英文原文:CSS Baseline,编译:飞鸟分享 译者注:网页设计布局中一直比较流行网格对齐,但只是针对水平的对齐,很少或者没 ...

  9. favicon的制作

    在head中插入如下标签: <link rel="shortcut icon" href="favicon.ico" />.然后把图标命名为favi ...

  10. poj1061 Exgcd

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> usin ...