const cs = [1, 2, 5]
const ac = 10
function h(n) {
const c = [0]
if (n === 0) {
return 0
}
for (let i = 1; i <= n; i++) {
let co = Infinity
console.log(co, c[i - 1] + 1);
if (i - 1 >= 0) co = Math.min(co, c[i - 1] + 1)
if (i - 2 >= 0) co = Math.min(co, c[i - 2] + 1)
if (i - 5 >= 0) co = Math.min(co, c[i - 5] + 1)
c[i] = co
}
console.log(c);
console.log(c[n]);
return c[n]
}
h(10)
动态规划硬币
最新推荐文章于 2024-08-18 10:54:05 发布