http://acm.hdu.edu.cn/showproblem.php?pid=5167

                Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3388    Accepted Submission(s): 886

Problem Description
Following is the recursive definition of Fibonacci sequence:

Fi=⎧⎩⎨01Fi−1+Fi−2i = 0i = 1i > 1

Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence.

 
Input
There is a number T shows there are T test cases below. (T≤100,000)
For each test case , the first line contains a integers n , which means the number need to be checked. 
0≤n≤1,000,000,000
 
Output
For each case output "Yes" or "No".
Sample Input
3
4
17
233
 
Sample Output
Yes
No
Yes
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  6263 6262 6261 6260 6259 
#include <iostream>
using namespace std;
int a[100];
int ct, flag; void init(){
a[0] = 0;
a[1] = 1;
ct += 2;
for(int i = 2; a[i - 1] <= 1000000000; i++){ //条件写为a[i]<=100000000000就崩了,注意是先i++,再判断条件的,所以会死循环
a[i] = a[i - 1] + a[i - 2];
ct++;
}
}
void dfs(int n, int k){
if(n == 1){
flag = 1;
return ;
}
for(int i = k; i >= 3; i--){
if(a[i] > n){
continue;
}
else if(n % a[i] == 0){
dfs(n / a[i], i); //注意:不是k-1而是i
}
if(flag) //剪纸
return ;
}
}
int main(){
std::ios::sync_with_stdio(false);
int t, n;
init();
cin >> t;
while(t--){
cin >> n;
if(n == 0 || n == 1){ //要特判
cout << "Yes" << endl;
}
else{
flag = 0;
dfs(n, ct - 1);
if(flag){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
}
return 0;
}

  

24-Fibonacci(dfs+剪枝)的更多相关文章

  1. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  2. *HDU1455 DFS剪枝

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. POJ 3009 DFS+剪枝

    POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...

  4. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  5. DFS(剪枝) POJ 1011 Sticks

    题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...

  6. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  7. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. LA 6476 Outpost Navigation (DFS+剪枝)

    题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...

  9. poj 1011 Sticks (DFS+剪枝)

    Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127771   Accepted: 29926 Descrip ...

  10. poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)

    Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

随机推荐

  1. ionic2——学习指引-学习资源汇总

    Ionic2 官网............................官网的文档非常好,超级全,一定要细心看中文文档.....................比较简单 Angular 2 官网.. ...

  2. 如何下载中文语言包让Eclipse汉化?

    Eclipse软件是JAVA开发必备的软件,对于英语不好的人而言面对英文代码还好,但是软件也是英语的那就头疼了,怎么解决?可以去官网下载中文语言包解压到Eclipse安装目录就可以汉化了.   工具/ ...

  3. angular复选框式js树形菜单(一)

    treeView.html <ul class="tree-view"> <li ng-repeat="item in treeData" n ...

  4. NHibernate常见错误汇总

    NHibernateSample.Data.Test.QueryHQLFixture.WhereTest: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException ...

  5. Agc001_D Arrays and Palindrome

    传送门 题目大意 给定一个元素和为$N$的有$M$个数的序列$A$,请你可以$A$元素排列的顺序,并需要构造一个有$K$个($K$可以自己定)数的数列,使得任意一个长度为$N$的字符串,若满足:前$A ...

  6. UVA - 11324 The Largest Clique (强连通缩点+dp)

    题目链接 题意:从有向图G中找到一个最大的点集,使得该点集中任意两个结点u,v满足u可达v或v可达u. 解法:先把同处于一个强连通分量中的结点合并(缩点),得到一张DAG图,在DAG上dp即可. 感觉 ...

  7. Java中print()、printf()、println()的区别?

    区别: 1.printf主要是继承了C语言的printf的一些特性,可以进行格式化输出 2.print就是一般的标准输出,输入信息后不会换行 3.println输入信息会换行 参照JAVA API的定 ...

  8. set/multiset容器

    一.二叉树基本概念 二叉树就是任何节点最多只允许有两个子节点.分别是左子节点和右子节点. 二叉搜索树,是指二叉树中的节点按照一定的规则进行排序,使得对二叉树中元素访问更加高效.二叉搜索树的放置规则是: ...

  9. 难道调用ThreadPool.QueueUserWorkItem()的时候,真是必须调用Thread.Sleep(N)吗?

    开门见山,下面的例子中通过调用ThreadPool.QueueUserWorkItem(WaitCallback callBack, object state)的方式实现异步调用: 1: class ...

  10. UVA548(二叉树遍历)

    You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...