Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LTTS - biễu diễn 1 số bằng tổng các số Fibonaci sao cho số chữ số Fibonaci xuất hiện là ít nhất
- #include <iostream>
- using namespace std;
- int f0=1;
- int f1=1;
- int f[1000];
- int n;
- int temp[100] = {0};
- void main()
- {
- cin>>n;
- f[0]=f0;
- f[1]=f1;
- int k=0;
- for(int i=2; i<1000; i++)
- {
- f[i]=f[i-1]+f[i-2];
- }
- int w = n;
- for(int i=0; i<1000; i++)
- {
- if(f[i]==n)
- {
- cout<<f[i]<<endl;
- return;
- }
- if(f[i]>n)
- {
- k= i-1;
- cout<<f[k]<<endl;
- break;
- }
- }
- w-=f[k];
- for(int i = k-1; i>=0; i--)
- {
- if(f[i]==w)
- {
- cout<<f[i]<<endl;
- return;
- }
- if(f[i]<w)
- {
- cout<<f[i]<<endl;
- w-=f[i];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement