符号三角形——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#来写,结果写到一半就觉得日了狗了...毕竟 ...
随机推荐
- Javascript实现时钟
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- sp_executesql的用法
之前做项目的时候负责一个成绩分析的模块儿,写存储过程的时候因为考试的科目是不固定的,所以导致查找成绩的sql语句也是动态的,就用到了sp_executesql,下面就来说一说它的用法 需求:表名是动态 ...
- Codeforces Round #130 (Div. 2) C. Police Station
题目链接:http://codeforces.com/contest/208/problem/C 思路:题目要求的是经过1~N的最短路上的某个点的路径数 / 最短路的条数的最大值.一开始我是用spf ...
- Win7 Object_Header之TypeIndex解析
在暴力搜索内存进程对象反隐藏进程这篇文章中,我们提到: Object Header偏移0×008处Type成员为对象类型值,相同类型的对象具有相同的值. 自Window 7开始, _OBJECT_ ...
- 获取内核当前执行模块和当前发生异常地址和线程异常Handler调用步骤
循环每个内核模块 统计模块大小 判断触发异常的地址属于那个模块.来确定模块 获取发生异常地址 nt!_EXCEPTION_RECORD +0x000 ExceptionCode : -21391605 ...
- lr_save_string 和 sprintf 的使用
lr_save_string 和 sprintf 的使用 一.lr_save_string 使用介绍1.该函数主要是将程序中的常量或变量保存为lr中的参数.格式: //将常量保存为参数 lr_save ...
- localhost和127.0.0.1 的区别
- mybatis做like模糊查询
http://www.cnblogs.com/cyttina/p/3894428.html
- xor方程组消元 UVA 11542 Square
题目传送门 题意:给n个数,选择一些数字乘积为平方数的选择方案数.训练指南题目. 分析:每一个数字分解质因数.比如4, 6, 10, 15,, , , , 令,表示选择第i个数字,那么,如果p是平方数 ...
- CSS-布局【1】-图片在div中垂直居中
方法一:通过增加100%高度行内块居中对齐 <!DOCTYPE html> <html> <head> <meta name="viewport&q ...