符号三角形——F
F. 符号三角形
64-bit integer IO format: Java class name:
+ + - + - + +
+ - - - - +
- + + + -
- + + -
- + -
- -
+
Input
Output
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的更多相关文章
- 【a502】符号三角形问题
Time Limit: 1 second Memory Limit: 32 MB [问题描述] 在一般情况下,符号三角形的第一行有n个符号.按照2个同号的下面是"+"号,2个异号的 ...
- OpenJudge 2990:符号三角形 解析报告
2990:符号三角形 总时间限制: 1000ms 内存限制: 65536kB 描述 符号三角形的第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“ ...
- 符号三角形(hdu 2510 搜索+打表)
符号三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 符号三角形_hdu_2510(深搜).java
http://acm.hdu.edu.cn/showproblem.php?pid=2510 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 2510 符号三角形 (DFS+打表)
符号三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- code vs 3376 符号三角形
3376 符号三角形 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 如下图是由14个“+”和14个“-”组 ...
- 【HDOJ】2510 符号三角形
暴力打表. #include <cstdio> ]={,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { while (scanf("%d" ...
- HDU 2510 - 符号三角形
DFS后打表 #include <iostream> using namespace std; ,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { int n; ...
- 使用F#来实现哈夫曼编码吧
最近算法课要求实现哈夫曼编码,由于前面的问题都是使用了F#来解决,偶然换成C#也十分古怪,报告也不好看,风格差太多.一开始是打算把C#版本的哈夫曼编码换用F#来写,结果写到一半就觉得日了狗了...毕竟 ...
随机推荐
- WPF 创建自定义窗体
在前面的一篇博客"WPF 自定义Metro Style窗体",展示了如何创建一个类似于Metro Style的Window,并在程序中使用.但是这个窗体不能够自由的改变大小.今天的 ...
- hdu 5288 数学 ****
给一个序列 定义函数f(l ,r) 为区间[l ,r] 中 的数ai不是在这个区间其他任意数aj的倍数 求所有f(l,r)之和 通过预处理,记录 a[i] 的左右边界(所谓的左右边界时 在从 a[i] ...
- 四种方案解决ScrollView嵌套ListView问题(转)
以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...
- barabasilab-networkScience学习笔记6-evolving networks
第一次接触复杂性科学是在一本叫think complexity的书上,Allen博士很好的讲述了数据结构与复杂性科学,barabasi是一个知名的复杂性网络科学家,barabasilab则是他所主导的 ...
- Arduino101学习(一)——Windows下环境配置
一.Arduino IDE下载 要开发Arduino 101/Genuino 101,你需要先安装并配置好相应的开发环境.下载地址 http://www.arduino.cn/thread-5838- ...
- hdu 5690 All x
All X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submiss ...
- PhpMyAdmin管理,登录多台远程MySQL服务器
法一: 可直接在config.inc.php里添加数据库连接信息即可 先$i++, 然后复制原来的配置信息后修改 不过这种方式需要将连接信息写在配置文件中,有点麻烦. 这种后面省事,不用填信息,选择一 ...
- dreamwaver cs6 主题配色方案
这是css代码效果 这是js效果 这是html效果 使用方法:1.将下列代码自制到一个文本文档中,将文档命名为Colors.xml. 2.将Colors.xml放到C:\Users\tom\AppDa ...
- 《用delphi开发共享软件》-15.2桌面提示器
打开一个配置文件: 打开一个配置文件 操作TStringGrid Procedure EmptyGrid(Var sg:TStringGrid); Var i:Integer; begin do sg ...
- CF#335 Freelancer's Dreams
Freelancer's Dreams time limit per test 2 seconds memory limit per test 256 megabytes input standard ...