본문으로 바로가기

algospot. PICNIC (미해결)

category Algorithm/문제 2021. 1. 10. 02:06

코드

 const pros = input.slice(1,input.length).map(v=>v.split(' ').map(v=>Number(v)));

 for(let i=0; i<pros.length; i+=2){
     const arr = pros.slice(i,i+2);
     let answer = 0;
     const number = arr[0];
     const mate = arr[1];

     dfs(0,[]);


     function dfs(index, line){
         if(line.length === number[0]){
             answer++;
             return ;
         }
         for(let i=index;i<mate.length;i+=2){
             if(dupCheck(line, [mate[i], mate[i+1]] )) {
                 line.push(mate[i]);
                 line.push(mate[i + 1]);
                 dfs(i + 2, line);
                 line.pop();
                 line.pop();
             }
         }
     }
     // console.log(`${i+1}번째 케이스 끝 : ${answer}`);
     console.log(answer);
 }


 //중복 체크 함수
 function dupCheck(arr1, [first, second]){
     return !(arr1.includes(first) || arr1.includes(second));
 }

뭐가 틀렸는지 모르겠다..

테스트 케이스는 잘 되고 차근차근 살펴봐도 틀릴 부분이 없는 것 같은데

'Algorithm > 문제' 카테고리의 다른 글

leetcode. Add Two Numbers  (0) 2021.01.14
leetcode. Two Sum  (0) 2021.01.11
baekjoon. 단어 정렬  (0) 2021.01.04
baekjoon. 통계학  (0) 2021.01.02
baekjoon. 수 정렬하기 3  (0) 2021.01.01