![[Java] 2140. Solving Questions With Brainpower - LeetCode Daily Challenge](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FkWM93%2FbtseTDKK66l%2FAAAAAAAAAAAAAAAAAAAAAKw_F6iH37HNt_ozwOWmwG08hAwLebhwFQ82wDto4aMK%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DHuPl8a1am%252FXFpNThablO%252BeE7pw0%253D)
[Java] 2140. Solving Questions With Brainpower - LeetCode Daily ChallengeP.S./leetcode2023. 5. 12. 14:32
Table of Contents
728x90
728x90
Solving Questions With Brainpower - LeetCode
Can you solve this real interview question? Solving Questions With Brainpower - You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri]. The array describes the questions of an exam, where you have to process the qu
leetcode.com
풀이
DFS를 이용해서, 해당 칸을 탐색할 수 있을 경우 탐색해서 모든 경우의수를 구한다음 최대값을 구하는 단순 DFS문제라고 생각했다.
class Solution {
public static long max = -1;
public long mostPoints(int[][] questions) {
if(questions.length==1) return questions[0][0];
boolean[] bl = new boolean[questions.length];
for(int i=0; i<questions.length; i++) {
dfs(questions[i][0], i, questions[i][1]+1, questions, bl);
}
return max;
}
public void dfs(long sum, int idx, int tmp, int[][] questions, boolean[] bl) {
if(idx >= questions.length) {
max = Math.max(max, sum);
return;
}
for(int i=idx; i<questions.length; i++) {
if(tmp != 0) {
tmp--;
continue;
}
if(bl[i]) return;
bl[i]=true;
dfs(sum+questions[i][0], i+1, tmp+questions[i][1]+1, questions, bl);
bl[i]=false;
}
max = Math.max(max, sum);
}
}
분명 IDE의 콘솔에서는 정답이 출력되는데 왜 틀렸다고 하는지 모르겠다. 나는 100이 나오는데 ㅡㅡ

머리 환기시키고 재도전해봐야겠다..
728x90
300x250
@mag1c :: 개발잘하고싶다
diehreo@gmail.com
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!