let l=readline().split(' ') let n=parseInt(l[0]),m=parseInt(l[1]) let res=new Array() let min =Math.min(n,m) let sum=0 function f(step){ if(step==min+1){ res.forEach((item)=>{ sum+=item }) if(sum==m) console.log(res.join(' ')) sum=0 return } res.push(step) f(step+1) res.pop() f(step+1) } let hh = f(1)
var readline = require('readline') const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) rl.on('line', function(line) { var tokens = line.split(' ') var sumsArr = [] findSumArr(parseInt(tokens[0]), parseInt(tokens[1]), [], sumsArr) sumsArr.sort().forEach(function(item) { console.log(item); }) }) function findSumArr(n, m, sumArr, sumsArr) { if(m < 1) {//m===0 sumsArr.push(sumArr.sort().join(' ')) return } if(n < 1) { return } // 如果n大于m,则将n赋值为m(大于m的值无用 if(n > m) { n = m } // 注意:这里不能直接使用 tmpArr=sumArr var tmpArr = [] sumArr.forEach(function(item) { tmpArr.push(item) }) // 1. 不将n放入数组 findSumArr(n-1, m, sumArr, sumsArr) // 2. 将n放入数组 tmpArr.push(n) findSumArr(n-1, m-n, tmpArr, sumsArr) }