Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved 보행자 천국 - 103MB 189.27ms #262

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
22 changes: 22 additions & 0 deletions Programmers/보행자천국/보행자천국_김현준.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
static int [][][] dp;
int MOD = 20170805;
public int solution(int m, int n, int[][] cityMap) {
int answer = 0;
dp = new int[m+1][n+1][2];
dp[0][0][0] = 1; // 0은 좌측, 1은 위에서 내려옴
for(int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
if(cityMap[i][j] == 0) {
dp[i][j+1][0] = (dp[i][j][0] + dp[i][j][1]) % MOD;
dp[i+1][j][1] = (dp[i][j][0] + dp[i][j][1]) % MOD;
} else if(cityMap[i][j] == 2) {
dp[i][j+1][0] = (dp[i][j+1][0] + dp[i][j][0]) % MOD;
dp[i+1][j][1] = (dp[i+1][j][1] + dp[i][j][1]) % MOD;
}
}
}
return (dp[m-1][n-1][0] + dp[m-1][n-1][1]) % MOD;

}
}
54 changes: 54 additions & 0 deletions Programmers/불량사용자/불량사용자_김현준.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.util.*;

class Solution {
static List<Set<String>> firstSet = new ArrayList<>();
static Set<Set<String>> finalSet = new HashSet<>();
static int ans = 0;
static boolean[] v;
public int solution(String[] user_id, String[] banned_id) {
int answer = 1;
// 가능한 모든 경우를 탐색
for(int i=0;i<banned_id.length;i++) {
char[] c = banned_id[i].toCharArray();
Set<String> set = new HashSet<>();
for(int j=0;j<user_id.length;j++) {
int cnt = 0;
for(int k=0;k<user_id[j].length();k++) {
// k 가 banned_id 보다 갯수가 많으면 x
if(k > c.length - 1) break;
if(c[k] == '*' || c[k] == user_id[j].charAt(k)) {
cnt++;
}

if(cnt == c.length && k == user_id[j].length()-1) {
set.add(user_id[j]);
}
}
}
firstSet.add(set);
}

System.out.println(firstSet.toString());
// 여기서 dfs로 순서 상관없이 조회가능한 갯수 체크
// v = new boolean[set.size()];
dfs(0, new HashSet<>(), banned_id.length);
// System.out.println(finalSet.toString());
return finalSet.size();
}

public static void dfs(int idx, Set<String> current, int size) {
// basis
if(idx == size) {
finalSet.add(new HashSet<>(current));
return;
}

for(String user : firstSet.get(idx)) {
if(!current.contains(user)) {
current.add(user);
dfs(idx + 1, current, size);
current.remove(user);
}
}
}
}