题目:
思路:
简单的组合问题,
循环遍历每一项,与现有的组合,遍历组合成新的数组,将结果加入现有组合
提交:
while(line = readline()) {
const num = Number(line)
const weights = readline().split(' ').map(item => Number(item))
const nums = readline().split(' ').map(item => Number(item))
let totalWeights = []
nums.forEach((item, index) => {
if (item) {
totalWeights = totalWeights.concat(new Array(item).fill(weights[index]))
}
})
// console.log(totalWeights)
let result = [0]
totalWeights.forEach(item => {
let newArr = []
result.forEach(subItem => {
newArr.push(subItem + item)
})
result = new Set([...result, ...newArr])
// console.log(result)
})
result = [...result].length
console.log(result)
}