24-Fibonacci(dfs+剪枝)
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
Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence.
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
4
17
233
No
Yes
#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+剪枝)的更多相关文章
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- *HDU1455 DFS剪枝
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- POJ 3009 DFS+剪枝
POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...
- poj 1724:ROADS(DFS + 剪枝)
ROADS Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10777 Accepted: 3961 Descriptio ...
- DFS(剪枝) POJ 1011 Sticks
题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...
- DFS+剪枝 HDOJ 5323 Solve this interesting problem
题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- LA 6476 Outpost Navigation (DFS+剪枝)
题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...
- poj 1011 Sticks (DFS+剪枝)
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127771 Accepted: 29926 Descrip ...
- 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 ...
随机推荐
- html5视频video积累
又是好几个月没有写东西,还是太懒散了~必须要教育下自己罗~ 这次做了个播放视频的移动H5,之前没有仔细玩过,好好记录下基本知识,还有遇到的一些坑,方便之后再次遇见后进行解决 一.基本 video标签在 ...
- git教程5-查看关系图与no fast forward融合
1.每一个提交相当于一个版本,版本都有版本号与之对应.通常通过git commit -m "name"为每次提交命名. 2.融合:即将次分支的最后一个版本添加到主分支上.当融合冲突 ...
- 如何选择MySQL数据库的安装方式
MySQL数据库安装有yum安装,rpm安装,二进制编译安装,cmake,或者make安装,但是选择什么样的安装方式则全看实际应用场景. 下为网友总结安装方式选择: 若是对数据库要求不太高的场景 ...
- centos 下配置oracle11gR2开机自启
这里使用的环境是 CentOS 6.6 ,并且已经装好了oracle11gR2 oracle启动分为两个步骤: 1.启动监听 2.启动服务 1.root 用户下修改ORATAB(将N该为Y): [ro ...
- Unity3D研究院之Assetbundle的实战(六十三)
http://www.xuanyusong.com/archives/2405 上一篇文章中我们相惜讨论了Assetbundle的原理,如果对原理还不太了解的朋友可以看这一篇文章:Unity3D研究院 ...
- 理解SQL查询的底层原理
阅读目录 一.SQL Server组成部分 二.查询的底层原理 本系列[T-SQL]主要是针对T-SQL的总结. T-SQL基础 [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础] ...
- Java代码使用正则验证和常用工具方法
1.正则验证邮箱 public static boolean checkEmail(String email){ boolean flag = false; try{ String check = & ...
- python list和元祖
一,元祖 在python中元祖是只能查询和读取的一组数据,在()内的赋值就是元祖,只有查询和读取的功能: 1.len()方法:查询元祖有多少个元素 s = (') print(len(s)) 结果: ...
- 11.Selenium+Python案例--百度
一.具体代码实现 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionCh ...
- win32 获取本机网卡信息(MAC地址,IP地址等)
由于一个需求需要获取网卡的MAC地址,就搜了一下,大部分都是COPY来COPY去的一些代码,有很多甚至不能直接运行或有还有内存泄漏.自己查了一下MSDN然后封装了一下: 需要注意,一个机器可能有多个网 ...