I am recently doing Minimum Fibonacci terms with sum equal to K. i have done using dp approach but tle. but why this problem works with greedy approach.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
I am recently doing Minimum Fibonacci terms with sum equal to K. i have done using dp approach but tle. but why this problem works with greedy approach.
Название |
---|
According to Zeckendorf's theorem any number can be uniquely described as a sum of Fibonacci numbers.
so,this unique representation comes from greedy approach ?
yes
I would like to say, that it isn't unique, unless you mention that the representation is such that no two consecutive fibonacci numbers ( Say $$$F_{n-1}$$$ and $$$F_{n}$$$ ) are used for the representation, because you can just use $$$F_{n+1}$$$ instead.
There is an optimal solution that uses each Fibonacci number at most once and never uses two consecutive Fibonacci numbers.
Proof: Take the lexicographically largest solution. It cannot use two consecutive numbers because such a solution would not be optimal (instead of F_n and F_{n+1} take just F_{n+2}). It cannot use 1 twice because using 2 once is better. It cannot use any bigger Fibonacci number twice because instead of F_n + F_n you can have F_{n+1} + F_{n-2} which gives you a lexicographically bigger solution with the same number of coins.
Each number has exactly one representation that uses each Fibonacci number at most once and never uses two consecutive Fibonacci numbers. The greedy algorithm constructs this representation and therefore its output is always optimal.