Алгоритмы на ruby: жадные алгоритмы

  • Published on
    14-Jun-2015

  • View
    2.813

  • Download
    9

Embed Size (px)

DESCRIPTION

О жадных алгоритмах

Transcript

<ul><li> 1. References . .10-11 23 2012 . 10-11 . .</li></ul> <p> 2. References (greedy) , . .: . 10-11 . . 3. References 1, 2, 5, 10, 20, 50 100 . N. N . 10-11 . . 4. References a1 = 1 &lt; a2 &lt; &lt; ak . N. N . 10-11 . . 5. References 1 , (). 2 : , ( ) . 3 ... . 4 ( ), . 10-11 . . 6. References 10-11 . . 7. References 1 . 2 , . . , . 3 : , . 4 : , . . 10-11 . . 8. References Listing 1: def give_coin ( coins , n ) i f c o i n s . i n c l u d e ?( n)puts n elsemax = c o i n s . f i n d _ a l l { | e l e m | e l e m &lt; n } . maxp u t s maxg i v e _ c o i n ( c o i n s , nmax ) end end coins = [1 ,2 ,5 ,10 ,20 ,50 ,100] n = 398 give_coin ( coin , n) 10-11 . . 9. References 10-11 . . 10. References 1 : . 2 , . 3 : , . 4 . 10-11 . . 11. References Listing 2: coins = [1 ,2 ,5 ,10 ,20 ,50 ,100] n = 48 w h i l e ( n != 0 ) max = c o i n s . f i n d _ a l l { | e l e m | elem</p>

Recommended

View more >