符号三角形——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#来写,结果写到一半就觉得日了狗了...毕竟 ...
随机推荐
- [SQL]oracle 的to_char、to_number、to_date用法
关键字: oracle 的to_char.to_number.to_date用法 TO_CHAR 是把日期或数字转换为字符串TO_DATE 是把字符串转换为数据库中得日期类型转换函数TO_NUMBER ...
- 关于socket——SO_SNDBUF and SO_RECVBUF
转自:http://blog.csdn.net/wf1982/article/details/38871521 参见 http://stackoverflow.com/questions/425741 ...
- TensorFlow
转自:http://blog.csdn.net/stdcoutzyx/article/details/51645396 本片博文是参考文献[1]的阅读笔记,特此声明 TensorFlow,以下简称TF ...
- JQuery初探
[TOC] jquery 通过jQuery,您可以选取(查询,query)HTML元素,并对它们执行"操作"(actions). jQuery 使用的语法是 XPath 与 CSS ...
- Vue#条件渲染
根据不同的条件,响应不同的事件. https://jsfiddle.net/miloer/zed5p1r3/ 可以用template来包装元素,当然浏览器的最终渲染结果不会包含它.我觉得主要用它来自定 ...
- 【项目经验】EasyUI Tree
ITOO5.0开始了,我参加了伟大的基础系统,从整体上来说,基础系统有三个职能: 1.自己的核心职能--选课(公共选修课,专业选修课),课表: 2.为其他系统提供真实数据: 3.维护信息 而近两三天, ...
- LoadRunner 脚本学习 -- 使用动态链接库
DLL = Dynamic Link Library DLL最重要的一个特点就扩展应用程序的特性. 再强大的工具也有不是万能的,通过调用动态库的方法极大地增强loadrunner的功能.当你在用loa ...
- js 判断数组的值是否有重复
方法一: var s = ary.join(",")+","; for(var i=0;i<ary.length;i++) { if(s.replace( ...
- CSS3_实现圆角效果box-shadow
1.outline的直角与圆角 来给个div: <div class="use-outline"></div> 来再给个样式: .use-outline{ ...
- js不间断平滑地自动向上滚动
<html> <head> <title>scroll up auto smooth</title> <style> *{ margin: ...