HDU
来源:互联网 发布:淘宝 中药材 编辑:程序博客网 时间:2024/06/07 14:54
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5167
题目描述
Description
Following is the recursive definition of Fibonacci sequence:
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,000T≤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
解题思路
斐波那契数列,判断输入的数字是否能用数列中的数相乘表示,
先打表,然后搜索,遇到可以整除的数字就除以它,然后继续搜索,直到它可以等于1,说明可以除尽,就说明可以表示。
为什么 i 是44呢,因为到第45个就超出了题目数据范围,可以打表自己试试
bool类型,dfs小知识
AC代码
#include<iostream> #include<algorithm> using namespace std;long long f[5000];bool dfs(int x, int n) { if(x == 1) return true; for(int i = n; i > 2; i--) { if(x % f[i] == 0) { if(dfs(x / f[i], i)) return true; } } return false;}int main () { int i; f[0] = 0; f[1] = 1; for(i = 2; i <= 44; i++) { f[i] = f[i-1] + f[i-2]; } int t; cin >> t; while(t--) { long long x; scanf("%lld", &x); if(x == 0) printf("Yes\n"); else if(dfs(x, i-1)) printf("Yes\n"); else printf("No\n"); } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- multiset<int, greater<int>> test 相关
- 欢迎使用CSDN-markdown编辑器
- POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
- js技术--BOM(open,close,右下角固定悬浮框)
- python re模块
- HDU
- oracle定义数组类型
- java基础(六):类和对象(1)
- 4:--2相对定位
- 了解比特币(区块链)
- JSP的配置教程
- Android基础,用户界面设计(布局)
- 排列组合(1)
- mybatis 缓存(三)缓存有关的设置以及属性