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.

# | User | Rating |
---|---|---|

1 | tourist | 3557 |

2 | Radewoosh | 3468 |

3 | Um_nik | 3429 |

4 | Petr | 3354 |

5 | Benq | 3286 |

6 | mnbvmar | 3280 |

7 | wxhtxdy | 3276 |

7 | LHiC | 3276 |

9 | ecnerwala | 3214 |

10 | yutaka1999 | 3190 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 191 |

2 | Radewoosh | 180 |

3 | tourist | 173 |

4 | Vovuh | 165 |

4 | antontrygubO_o | 165 |

6 | PikMike | 164 |

7 | rng_58 | 160 |

8 | Um_nik | 156 |

8 | majk | 156 |

10 | 300iq | 154 |

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.

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/20/2019 03:01:56 (h2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

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.