dfs로 라이언이 화살을 맞히는 모든 경우의 수를 완전탐색을 진행했다.
class Solution {
static int[] wrong={0,0,0,0,0,0,0,0,0,0,0};
static int res=-1;
static int[] answer;
public int[] solution(int n, int[] info) {
int[] rion=new int[11];
answer =new int[11];
dfs(n,0,rion,info);
if(res==-1)answer=new int[]{-1};
return answer;
}
static void dfs(int rem,int idx,int[] rion,int[] info){
if(idx>10)return;
if(rem==0){
int pScore=0,rScore=0;
for(int i=0;i<11;i++){
if(info[i]>=rion[i] && info[i]!=0){
pScore+=10-i;
}
else if(info[i]<rion[i] && rion[i]!=0){
rScore+=10-i;
}
}
if(rScore<=pScore)return;
if(res<rScore-pScore){
for(int i=0;i<11;i++){
answer[i]=rion[i];
}
res=rScore-pScore;
}
else if(res==rScore-pScore){
for(int i=10;i>-1;i--){
if(answer[i]>rion[i])break;
else if(answer[i]<rion[i]){
for(int j=0;j<11;j++){
answer[j]=rion[j];
}
break;
}
else continue;
}
}
return;
}
rion[idx]++;
dfs(rem-1,idx,rion,info);
rion[idx]--;
dfs(rem,idx+1,rion,info);
}
}
#dfs