๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 2775๋ฒˆ : ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 9. 24.

 

 

Algorithm

-  ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ -

 


 

๋ฌธ์ œ

ํ‰์†Œ ๋ฐ˜์ƒํšŒ์— ์ฐธ์„ํ•˜๋Š” ๊ฒƒ์„ ์ข‹์•„ํ•˜๋Š” ์ฃผํฌ๋Š” ์ด๋ฒˆ ๊ธฐํšŒ์— ๋ถ€๋…€ํšŒ์žฅ์ด ๋˜๊ณ  ์‹ถ์–ด ๊ฐ ์ธต์˜ ์‚ฌ๋žŒ๋“ค์„ ๋ถˆ๋Ÿฌ ๋ชจ์•„ ๋ฐ˜์ƒํšŒ๋ฅผ ์ฃผ์ตœํ•˜๋ ค๊ณ  ํ•œ๋‹ค.

 

์ด ์•„ํŒŒํŠธ์— ๊ฑฐ์ฃผ๋ฅผ ํ•˜๋ ค๋ฉด ์กฐ๊ฑด์ด ์žˆ๋Š”๋ฐ, “a์ธต์˜ bํ˜ธ์— ์‚ด๋ ค๋ฉด ์ž์‹ ์˜ ์•„๋ž˜(a-1)์ธต์˜ 1ํ˜ธ๋ถ€ํ„ฐ bํ˜ธ๊นŒ์ง€ ์‚ฌ๋žŒ๋“ค์˜ ์ˆ˜์˜ ํ•ฉ๋งŒํผ ์‚ฌ๋žŒ๋“ค์„ ๋ฐ๋ ค์™€ ์‚ด์•„์•ผ ํ•œ๋‹ค” ๋Š” ๊ณ„์•ฝ ์กฐํ•ญ์„ ๊ผญ ์ง€ํ‚ค๊ณ  ๋“ค์–ด์™€์•ผ ํ•œ๋‹ค.

 

์•„ํŒŒํŠธ์— ๋น„์–ด์žˆ๋Š” ์ง‘์€ ์—†๊ณ  ๋ชจ๋“  ๊ฑฐ์ฃผ๋ฏผ๋“ค์ด ์ด ๊ณ„์•ฝ ์กฐ๊ฑด์„ ์ง€ํ‚ค๊ณ  ์™”๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ, ์ฃผ์–ด์ง€๋Š” ์–‘์˜ ์ •์ˆ˜ k์™€ n์— ๋Œ€ํ•ด k์ธต์— nํ˜ธ์—๋Š” ๋ช‡ ๋ช…์ด ์‚ด๊ณ  ์žˆ๋Š”์ง€ ์ถœ๋ ฅํ•˜๋ผ. ๋‹จ, ์•„ํŒŒํŠธ์—๋Š” 0์ธต๋ถ€ํ„ฐ ์žˆ๊ณ  ๊ฐ์ธต์—๋Š” 1ํ˜ธ๋ถ€ํ„ฐ ์žˆ์œผ๋ฉฐ, 0์ธต์˜ iํ˜ธ์—๋Š” i๋ช…์ด ์‚ฐ๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

๋ฌธ์ œ ํ’€๊ธฐ

const readline = require("readline");
const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout,
});
let input = [];
rl.on("line", function (line) {
	input.push(+line.toString());
}).on("close", function () {
	input.shift();
	while (true) {
		let apartInfo = [];
		let floor = input.shift();
		let ho = input.shift();
		let zeroho = [];
		for (let i = 1; i <= ho; i++) {
			zeroho.push(i);
		}
		apartInfo.push(zeroho);
		for (let i = 0; i < floor; i++) {
			let info = [];
			for (let j = 1; j <= zeroho.length; j++) {
				info.push(
					apartInfo[i].slice(0, j).reduce((past, curr) => past + curr, 0)
				);
			}
			apartInfo.push(info);
		}
		console.log(apartInfo[apartInfo.length - 1][apartInfo[0].length - 1]);
		if (!input.length) break;
	}
	process.exit();
});

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€