From 517ab11ecef96c2ba38c036bbe02da6e18fcb582 Mon Sep 17 00:00:00 2001 From: YangFong <70502828+YangFong@users.noreply.github.com> Date: Thu, 3 Feb 2022 19:12:49 +0800 Subject: [PATCH 1/2] docs: add a description of the solution to lc problem: No.1414 No.1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K --- .../README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md index f5f4924ce11b3..8c1ab5b6c232e 100644 --- a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md +++ b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md @@ -53,6 +53,22 @@ +由于斐波那契数特点,数字重用在此题中是一个烟雾弹。举例推导:`k = 288`,数列(局部)`1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377`,可以由两个 144,或 `233 + 55` 组成;`k = 10`,可以由两个 5 或 `8 + 2` 组成。 + +由此可以使用贪心策略,逆向遍历斐波那契数列,进行暴力查找: + +```txt +FIND-MIN-FIBONACCI-NUMBERS(k) + r = 0 + for n in f { + if k >= n + k -= n + r++ + if k === 0 + return res + } +``` + ### **Python3** From d823c18a92ce7c517fdbd4f461d72efe11b8f06c Mon Sep 17 00:00:00 2001 From: YangFong <70502828+YangFong@users.noreply.github.com> Date: Thu, 3 Feb 2022 19:14:24 +0800 Subject: [PATCH 2/2] fix: fix pseudocode format --- .../README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md index 8c1ab5b6c232e..9daf007eb8393 100644 --- a/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md +++ b/solution/1400-1499/1414.Find the Minimum Number of Fibonacci Numbers Whose Sum Is K/README.md @@ -60,13 +60,12 @@ ```txt FIND-MIN-FIBONACCI-NUMBERS(k) r = 0 - for n in f { + for n in f if k >= n k -= n r++ if k === 0 return res - } ```