题解 | 称砝码

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    const types = parseInt(await readline());
    const weights = (await readline()).split(" ").map(Number);
    const counts = (await readline()).split(" ").map(Number);
    let set = new Set();
    set.add(0);
    for (let i = 0; i < types; i++) {
        const weight = weights[i];
        const count = counts[i];
        const tempArray = Array.from(set);
        for (let j = 1; j <= count; j++) {
            for (let k = 0; k < tempArray.length; k++) {
                set.add(tempArray[k] + weight * j);
            }
        }
    }
    console.log(set.size);
})();

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务