algorithm - Ways to achieve N with some given integers -


this question has been asked in facebook's test : suppose there's game in score either 2, 3 or 7 in each turn. in how many ways can achieve score of x?

well it's typical knapsack problem, or more specific, coin-change problem.

we have several ways solve kind of problem, solve using dynamic programming easily.

this page explained solution quite well, please digest on own pace :)

for quick look, here pseudo code problem:

int coins[3] = {2, 3, 7};  (int = 0; < 5; ++i)       (int j = coins[i]; j <= x; ++j)           dp[j] += dp[j - coins[i]]; 

you can try this, similar problem on uva.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -