www.welcomekakao.com/learn/courses/30/lessons/42890
코딩테스트 연습 - 후보키
[["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]] 2
www.welcomekakao.com
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
bool possi(vector<int> &vec,int now){
for(int i=0;i<vec.size();i++){
if((vec[i]&now)==vec[i]) return false;
}
return true;
}
int solution(vector<vector<string>> relation) {
int answer;
vector <int> ans;
int n = relation.size();
int m = relation[0].size();
for(int i=1;i<(1<<m);i++){
set <string> s;
for(int j=0;j<n;j++){
string now = "";
for(int k=0;k<m;k++){
if(i&(1<<k))now+=relation[j][k];
}
s.insert(now);
}
if(s.size()==n&&possi(ans,i)) ans.push_back(i);
}
answer=ans.size();
return answer;
}
'개발자 > algorithm' 카테고리의 다른 글
백준 19238번 : 스타트 택시 (c++) (0) | 2020.10.01 |
---|---|
백준 19237번 : 어른 상어 (c++) (0) | 2020.10.01 |
2019 카카오 코딩테스트 5번 : 길 찾기 게임 (c++) (0) | 2020.09.02 |
2018 카카오 코딩테스트 5번 : 뉴스 클러스터링 (c++) (0) | 2020.09.01 |
2018 카카오 코딩테스트 3번 : 캐시 (c++) (0) | 2020.09.01 |