본문 바로가기
Programming/Algorithm

백준 가르침

by OKOK 2018. 3. 28.

 1. 단어를 학습시키고, 이것이 다른 단어를 읽을 수 있는지 


2. 중복이 아닌 조합을 하기 위해서 뒤로만 흘러가도록 설정할 수 있습니다.

그래서 그때의 아리를 시작점으로 하고 들어가도록 해야 합니다.

하지만, if(depth > 'z' - i + 1 이것이 어디에 사용되는 것인지 궁금합니다. 


3. 


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

string str;

int word[50][15];

int alpha[200];

int ans;

int maxVal;

int N, K;

int k;

int wlen;

int cnt;

int read;


void problemIn() {

cin >> N >> K;

for (int i = 0; i < N; i++) {

cin >> str;

int length = str.size();

for (int j = 4; j < length-4 ; j++) {

word[i][j - 4] = str[j];

}

}

}


void dfs(int depth, char start) {


if (depth < 0) return;



if (depth == 0) {

read = 0;

for (int i = 0; i < N; i++) {

for (int j = 0; ; j++) {

if (word[i][j] == 0) {

wlen = j;

break;

}

}

cnt = 0;

for (int j = 0; j < wlen; j++) {

if (alpha[word[i][j]]) cnt++;

}

if (cnt == wlen) {

read++;

}

}

ans = max(ans, read);

return;

}


for (int i = start; i < 'z' + 1; i++) {

if (alpha[i] == 0) {

if ( depth >  'z' - i + 1 ) continue;



alpha[i] = 1;

dfs(depth - 1, i+1);

alpha[i] = 0;

}

}

}


void solve() {


alpha['a'] = 1;

alpha['c'] = 1;

alpha['i'] = 1;

alpha['t'] = 1;

alpha['n'] = 1;


k = K - 5;

dfs(k, 'a');


}


int main() {

problemIn();

solve();

cout << ans << endl;

return 0;