符号三角形——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#来写,结果写到一半就觉得日了狗了...毕竟 ...
随机推荐
- codeforces 45C C. Dancing Lessons STL
C. Dancing Lessons There are n people taking dancing lessons. Every person is characterized by his ...
- POJ 1984 Navigation Nightmare 带全并查集
Navigation Nightmare Description Farmer John's pastoral neighborhood has N farms (2 <= N <= ...
- 小甲鱼PE详解之IMAGE_DOS_HEADER结构定义即各个属性的作用(PE详解01)
(注:最左边是文件头的偏移量.) IMAGE_DOS_HEADER STRUCT { +0h WORD e_magic // Magic DOS signature MZ(4Dh 5Ah) ...
- hash 分区的用途是什么?
Hash partitioning enables easy partitioning of data that does not lend itself to rangeor list partit ...
- Android 退出Activity
在一个Process或一个处理线程中退出Activity可以用context来退出,如下: ((Activity)context).finish(); Android程序有很多Activity,比如说 ...
- hdu 1370 Biorthythms 中国剩余定理
Biorhythms Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 阿里云 OSS+CDN
https://promotion.aliyun.com/ntms/ossedu2.html https://www.aliyun.com/act/aliyun/ossdoc.html 对象存储(Ob ...
- js的一些小笔记,(不定期更新)
2个$的用法$本身并无特定意义,它表示什么意思要看是如何定义的,如果没有定义就便是两个$,可能是变量名的开始.一般是一个函数,用来代替document.getElementByIdfunction $ ...
- Codeforces Round #371 (Div. 2) - B
题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...
- 选项卡 tab切换
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...