Published
Edited
Mar 9, 2021
Insert cell
md`# algorithm-硬币
目前市面上的纸币主要有1元,5元,10元,20元,50元、100元六种,如果要买一件商品x元,有多少种货币组成方式?
`
Insert cell
countWays(100)
Insert cell
countWays = n => {
// write code here
let coins = [1, 5, 10, 20];
let dp = [];
dp[0] = 1;
for (let i = 0; i < 4; ++i) {
for (let j = coins[i]; j <= n; ++j) {
if (isNaN(dp[j])) {
dp[j] = 0;
}
dp[j] = (dp[j] + dp[j - coins[i]]) % 1000000007;
}
}
console.log(dp);
return dp[n];
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more