原题目:https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/
思路:
贪心策略:从大向前拿,可以得到的数目最小
代码:
class Solution {
public:
int findMinFibonacciNumbers(int k) {
vector<int> res;
int a=0,b=1;
while(b <= k){
int tmp = a;
a=b;b=tmp + b;
res.push_back(a);
}
int count = 0;
for(int i=res.size()-1;i>=0;i--){
if(k-res[i] > 0){
count++;k -= res[i];
}
else if(k-res[i]==0){
count++;return count;
}
}
return -1;
}
};