532

 

10364

 

307

 

622

 

624

 

11057

Another way:

 

10667

 

10074

 

108

 

836

This problem also can be solved using Dynamic Programming.

Similar problems are : uva 108, uva 10074,uva 10667; These can be solved using the same algorithm.