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
Post a Comment