알고리즘
프로그래머스 PCCP 모의고사 2번 (JAVA)
박카스마시며코딩
2022. 9. 24. 21:17
https://school.programmers.co.kr/learn/courses/15008/lessons/121684
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
저는 순열을 통해 문제를 해결하였습니다.
순열을 통해 모든 상황을 고려해 가장 높은 점수를 찾았습니다.
class Solution {
public int solution(int[][] ability) {
int peopleCnt = ability.length;
int sportCnt = ability[0].length;
boolean[] used = new boolean[peopleCnt];
int answer = cal(0,used,ability,peopleCnt,sportCnt);
return answer;
}
private static int cal(int depth, boolean[] used,int[][] ability,int peopleCnt,int sportCnt){
if(depth == sportCnt){
return 0;
}
int result = 0;
for(int i = 0 ; i < peopleCnt ; i++){
if(used[i]){
continue;
}
used[i] = true;
result = Math.max(result,cal(depth+1,used,ability,peopleCnt,sportCnt)+ability[i][depth]);
used[i] = false;
}
return result;
}
}