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. Kali 2.0 日常软件

    目的 如果你用Kali作为学习安全之类的作业,那么他预装的一些软件已经够用了,但是,如果你打算用它来当做日常主要OS,那么安装一些常用软件就是一项重要作业. 软件 如果你是在标准用户下安装,别忘了su ...

  2. 总结js创建object的方式(对象)

    1.使用new操作符后跟Object构造函数 如: var person = new Object(); 可以写成 var person = {}; person.name = "kitty ...

  3. python--*args和**kwargs可变参数

    先来看个例子: #! /usr/bin/env python #coding=utf-8 def foo(*args, **kwargs): print('args=',args) print('kw ...

  4. LeetCode OJ:Count Complete Tree Nodes(完全二叉树的节点数目)

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  5. svn默认地址老发生改变,记下默认路径

    C:\Users\Administrator\AppData\Roaming\Subversion

  6. 完成一个servlet 就要在web.xml里面配一个映射,这样就有一个路径供我们 使用????? servlet从页面接收值?

    最后,最容易忘记的是:在dao层中 调用xml里的删除sql语句 后面需要人为加上事务提交.一定要! sqlSession.commit();//jdbc是自动提交,但是mybatis中不是自动提交的 ...

  7. 2017.11.28 Enginering management:problem-solving ability

    Today,my colleague is on bussiness trip. going to customer factory in jiangxi. slove the color diffe ...

  8. 转载:Java就业企业面试问题-电商项目

    转载: http://blog.csdn.net/qq_33448669/article/details/73657642

  9. node.js 笔记(一)

    参考:https://github.com/alsotang/node-lessons 感谢!!! 本文属于小白入门级笔记,请大牛自动屏蔽!!! 1.     开发环境 os: 10.12.6 nod ...

  10. Gradle的快速入门

    1.基础知识: Gradle提供了:构建项目的框架.但是其中起作用的是Plugin. Gradle在默认情况下提供了很多常用的Plugin.例如:构建Java的Plugin.还有war.Ear等. G ...