山东省第7届省赛 B题 Fibonacci
2016-06-10 19:27
225 查看
Fibonacci
Time Limit: 2000MS Memory limit: 131072K
题目描述
Fibonacci numbers are well-known as follow:Now given an integer N, please find out whether N can be represented as the sum of several Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers.
输入
Multiple test cases, the first line is an integer T (T<=10000), indicating the number of test cases.Each test case is a line with an integer N (1<=N<=109).
输出
One line per case. If the answer don’t exist, output “-1” (without quotes). Otherwise, your answer should be formatted as “N=f1+f2+…+fn”. N indicates the given number and f1, f2, … , fn indicating the Fibonacci numbers in ascendingorder. If there are multiple ways, you can output any of them.
示例输入
4
5
6
7
100
示例输出
5=5
6=1+5
7=2+5
100=3+8+89
提示
来源
“浪潮杯”山东省第七届ACM大学生程序设计竞赛示例程序
暴力打表然后用n递减就ok了ACcode:
#include <bits/stdc++.h> #define maxn 1005 #define mod 1000000007 #define ll long long using namespace std; ll dp[55],ans[55]; int main(){ dp[0]=dp[1]=1; dp[2]=2; for(int i=3;;++i){ dp[i]=dp[i-1]+dp[i-2]; if(dp[i]>1e9)break; } int n,loop; scanf("%d",&loop); while(loop--){ scanf("%d",&n); printf("%d=",n); int i=44,tot=0; while(n){ if(n>=dp[i]){ ans[++tot]=dp[i]; n-=dp[i]; } --i; } for(int i=tot;i>1;--i)cout<<ans[i]<<"+"; cout<<ans[1]<<'\12'; } return 0; }
相关文章推荐
- 基于 Jython 的大型应用系统动态实现
- SQL联合查询(内联、左联、右联、全联)的语法
- CSDN Markdown 公式指导手册
- 由工业4.0想到的
- 【风马一族_Python】 决策树
- Deep Learning
- 下午回来才后知百密于一疏忽
- hdu 4288 Coder(线段树)
- D
- JAVA中复写equals方法
- leetcode-java-31. Next Permutation
- Java面向对象
- 全面解析Linux 内核 3.10.x - 调度算法 - Linux 调度器
- 山东省第7届省赛 A题 Julyed
- html之 rel="external nofollow"
- 安卓手机蓝牙控制智能小车 android程序设计
- 面试题
- RN学习过程中遇到的问题记录
- html5 drop drag实现购物车加入书
- java学习笔记:管道流PipedInputStream和PipedOutputStream