issues
search
2024-TEAM-05
/
algorithm-for-kakao
์นด์นด์ค ๊ธฐ์ถ ๋ฌธ์ ๊ฐ์ฆ์๐ฃ
0
stars
0
forks
source link
[2022 KAKAO BLIND RECRUITMENT] ์๊ถ๋ํ
#21
Open
uijin-j
opened
1 month ago
uijin-j
commented
1 month ago
๐
์๊ถ๋ํ
hye-on
commented
1 month ago
Language : C++
์ฑ๋ฅ
์ฝ๋ ํ์ด
```cpp #include
#include
#include
#include
using namespace std; //08:52 //0์ ์, 1์ ๋๋ // visit์ฒ๋ฆฌ ๋์ dfs //์ ์ชฝ์ ์ต๋ ์์ ๊ฐ์ ธ์ฌ ์ ์๋ ๊ฐ์ #include
#include
#include
#include
using namespace std; //k์ ์ ๋งํ ์ ์๊ฐ k ์ ์ ๊ฐ์ ธ๊ฐ. ๊ฐ์ผ๋ฉด ์ดํผ์น๊ฐ ๊ฐ์ ธ๊ฐ //์ข ์ ์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ ์ดํผ์น๋ฅผ ์ฐ์น์๋ก ๊ฒฐ์ //๋ผ์ด์ธ์ด ๊ฐ์ฅ ํฐ ์ ์ ์ฐจ์ด๋ก ์ฐ์นํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์ฌ๋ฌ ๊ฐ์ง ์ผ ๊ฒฝ์ฐ, ๊ฐ์ฅ ๋ฎ์ ์ ์๋ฅผ ๋ //๋ง์ด ๋งํ ๊ฒฝ์ฐ //ํฌ ํฌ์ธํฐ? // ๋ฐฑํธ๋ํน! int p[11]; int sum =55; int mySum =0; int maxS; vector
ans(11); vector
result(11); vector
info; void checkAns(vector
num){ int yourS =0; int myS =0; for(int i=0;i<11;i++){ int score = 10-i; if(info[i]
=num[i] && info[i]>=1){ yourS+=score; } } if(myS>yourS){ if(myS-yourS>maxS){ //๊ฐ์ฅ ํฐ ์ ์ ์ฐจ์ด maxS = myS-yourS; ans = num; }else if(myS-yourS == maxS){ for(int i=10;i>=0;i--){ if(ans[i]>num[i]) return; else if(ans[i]
num){ if(rn<0){ return; } if(depth==11){ //๋ต์ด ๋ ์ ์๋์ง ์ฒดํฌ if(rn>0) num[10] =rn; checkAns(num); return; } int t = info[depth]+1; num[depth] = t; recursion(depth +1 ,rn-t , num); //๊ณผ๋ ๋ง์ถค num[depth] =0; recursion(depth +1 ,rn , num); // ๊ณผ๋ ๋ชป๋ง์ถค } vector
solution(int n, vector
_info) { vector
answer; info = _info; recursion(0,n,result); for(int i=0;i<11;i++) if(ans[i]>=1) return ans; answer.push_back(-1); return answer; } ```
์ฝ๋ฉํธ
- ํฌํฌ์ธํฐ๋ก ์ ๊ทผํ๋ค๊ฐ ์๋์๊ณ ๊ฒฐ๊ตญ ๋ฐฑํธ๋ํน์ ์ด์ฉํ ์ํ + ์กฐ๊ฑด ๊ผผ๊ผผํ ์ฝ๊ธฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. - ๊ฐ์ฅ ํฐ ์ ์๊ฐ ์๋๋ผ <๊ฐ์ฅ ํฐ ์ ์์ฐจ์ด>๋ฅผ ๋์ณค์๋ค์.. ์นด์นด์ค๋ ๋ฌธ์ ๊ผผ๊ผผํ..
uijin-j
commented
1 month ago
๐ ๋๊ธ ํ ํ๋ฆฟ
Language : Java
์ฑ๋ฅ
์ฝ๋ ํ์ด
```java import java.util.*; // 16:42 START! // ์ด๋ ต๋น.. class Solution { /** * ๋ณด์๋ง์ ๋ฐฐ๋ญ ๋ฌธ์ ๊ฐ ์๊ฐ๋จ! (์ด๋์ ์ป๊ธฐ ์ํด ์์ค๋ ์์) * - ์จ์ผํ๋ ํ์ด => ์์ค => ๋ฐฐ๋ญ ๋ฌธ์ ์์ ๋ฌด๊ฒ * - ์ป์ ์ ์๋ ์ ์ => ์ด๋ => ๋ฐฐ๋ญ ๋ฌธ์ ์์ ๊ฐ์น * * ๊ฒฐ๊ตญ ํ์ด๋ฅผ ๋ดค๋๋.. ์ํ๋ฌธ์ ์๋ค.. */ int[] ryan = new int[11]; int[] apeach = new int[11]; int[] answer = new int[11]; int maxDiff = 0; public int[] solution(int n, int[] info) { apeach = info; dfs(0, n); return maxDiff == 0 ? new int[]{-1} : answer; } private void dfs(int level, int remain) { if(level == 10) { ryan[10] = remain; // ๋จ์ ํ์ด์ 0์ ์๊ธฐ int rScore = 0; int aScore = 0; for(int i = 0; i <= 10; ++i) { if(ryan[i] > apeach[i]) rScore += 10 - i; else if(apeach[i] > 0) aScore += 10 - i; } if(rScore - aScore > maxDiff) { maxDiff = rScore - aScore; answer = copy(ryan); } if(rScore - aScore == maxDiff) { for(int i = 10; i >= 0; --i) { if(ryan[i] > answer[i]) { answer = copy(ryan); break; } if(answer[i] > ryan[i]) break; } } return; } // level ๊ณผ๋ ์ ๋ผ์ด์ธ์ด ๋ง์ถค if(apeach[level] + 1 <= remain) { ryan[level] = apeach[level] + 1; dfs(level + 1, remain - (apeach[level] + 1)); ryan[level] = 0; } // level ๊ณผ๋ ์ ๋ผ์ด์ธ์ด ์ ๋ง์ถค dfs(level + 1, remain); } public int[] copy(int[] arr) { int[] answer = new int[11]; for(int i = 0; i <= 10; ++i) { answer[i] = arr[i]; } return answer; } } ```
์ฝ๋ฉํธ
- n์ด ์์์ ์ํ์ผ๋ก ํ ์ ์๋๋ฐ, ๊ดํ ๋ ์ด๋ ต๊ฒ ์ ๊ทผํ๋ค์๐ฅฒ ํญ์ ์๊ฐ ๋ณต์ก๋๋ฅผ ๋จผ์ ๊ณ์ฐํด์ผ ๋ ๊ฒ ๊ฐ๋ค์ฉ..
๐ ์๊ถ๋ํ