정다윤 풀이
/* 치킨의 종류에 대한 모든 3가지 combinations(조합)에 대해, 각 회원의 만족도 최댓값을 모두 탐색하는 브루트 포스 방법. */ const filePath = process.platform === "linux" ? "/dev/stdin" : "input.txt"; let input = require("fs").readFileSync(filePath).toString().trim().split("\n"); let [N, M] = input.shift().split(" ").map(Number); const combination = (arr, selectNumber) => { const results = []; if (selectNumber === 1) return arr.map((el) => [el]); arr.forEach((fixed, index, origin) => { const rest = origin.slice(index + 1); const combinations = combination(rest, selectNumber - 1); const attached = combinations.map((el) => [fixed, ...el]); // 결과 results.push(...attached); // 경우의 수 추가 }); return results; }; const allCases = combination( [...new Array(M)].map((_, i) => i), 3 ); const satisfyArr = input.map((str) => str.split(" ").map(Number)); let answer = 0; // 모든 치킨 조합 for (let [a, b, c] of allCases) { let sum = 0; for (let j = 0; j < N; j++) { // 가장 큰 만족도만 골라서 sum sum += Math.max(satisfyArr[j][a], satisfyArr[j][b], satisfyArr[j][c]); } answer = Math.max(answer, sum); } console.log(answer);
김민수 풀이
let [num, ...input] = require('fs').readFileSync(__dirname + "/../input.txt").toString().trim().split("\n"); // let [num, ...input] = require('fs').readFileSync("/dev/stdin").toString().trim().split("\n"); const [N, M] = num.split(' ').map(Number); input = input.map(e => e.trim().split(' ').map(Number)) let max = 0; for(let i = 0; i < M-2; i++){ for(let j = i+1; j < M-1; j++){ for(let k = j+1; k < M; k++){ max = Math.max(max, input.map(e => Math.max(e[i] , e[j] , e[k])).reduce((a, b) => a + b, 0)); } } } console.log(max);
안재현 풀이
하송희 풀이
const fs = require("fs"); const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt"; let [info, ...chickens] = fs.readFileSync(filePath).toString().trim().split("\n"); let [n, m] = info.split(" "); let result = 0; let chickensArr = []; chickens.forEach((ele) => { chickensArr.push(ele.split(" ")); }); if (+n <= 3 || +m == 3) { // 사람이 3명 이하거나, 치킨 종류가 3개일 때 chickens.forEach((ele) => { result += Math.max(...ele.split(" ")); }); return console.log(result); } for (i = 0; i < +m - 2; i++) { for (j = i + 1; j < +m - 1; j++) { for (k = i + 2; k < +m; k++) { let tmpMax = 0; chickensArr.forEach((ele) => { tmpMax += Math.max(+ele[i], +ele[j], +ele[k]); }); if (tmpMax > result) result = tmpMax; } } } console.log(result);