题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void (async function () { // Write your code here // while(line = await readline()){ // let tokens = line.split(' '); // let a = parseInt(tokens[0]); // let b = parseInt(tokens[1]); // console.log(a + b); // } let num = await readline(); let weightStr = await readline(); let countStr = await readline(); let weights = weightStr.split(" "); let counts = countStr.split(" "); let fama = []; for(let i = 0; i < weights.length; i++) { for(let j = 0; j < counts[i]; j++) { fama.push(+weights[i]) } } let set = new Set(); set.add(0); for (const f of fama) { let arr = Array.from(set); for (const s of arr) { set.add(s + f); } } console.log(set.size) })();