: ๋ฐฑํธ๋ํน์์ ์กฐ๊ฑด๋ถ๋ก ์ฌ์ฉ๋๋ ๊ฐฑ์ ์ฉ ๋ณ์๋ ์ ์ญ์ผ๋ก ์ฌ์ฉํ์ง ๋ง๊ณ ,
์ธ์๋ก ๋ณด๋ด์ ์ฒ๋ฆฌํ์.
: ์กฐํฉ์ผ๋ก ํ๋ ค๊ณ ํ๋๋ฐ, ๋ญ๊ฐ ๋ฌธ์ ์ผ๊น...
-> ๋๋ 21๊ฐ ์ค์์ k - 5๊ฐ๋งํผ ์กฐํฉ์ ๊ตฌํ๋ ค๊ณ ํ๋๋ฐ,,,,
์ด๋ ๊ฒ ๋๋ฉด ์๊ฐ ๋ณต์ก๋ ์์ฒญ ์ปค์ง.
https://velog.io/@ssssujini99/%EB%B0%B1%EC%A4%80C1062%EB%B2%88%EA%B0%80%EB%A5%B4%EC%B9%A8
#include <chrono> // std::chrono::miliseconds
#include <iostream>
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include <vector>
using namespace std;
#include <condition_variable>
#include <shared_mutex>
#include <unordered_map>
#include <algorithm>
int main()
{
// a n t a t i c a
// a n t i c -> ์ฌ๊ธฐ 5๊ฐ์ง๋ ๋ฌด์กฐ๊ฑด ์์์ผ ํจ.
// 26 - 5 ์ค 21๊ฐ์์ ( k - 5 ) ๋งํผ์ ์กฐํฉ์ ์งํํด์ผ ํจ.
// k๊ฐ 6 ์ด๋ผ๋ฉด 21๊ฐ์ ์ํ๋ฒณ์ค์์ 1๊ฐ๋ฅผ ์ ํํด์ ์กฐํฉ
// 5๊ฐ ๊ธ์๋ ๋ฌด์กฐ๊ฑด์ ์ผ๋ก ์์์ผ๋ง
// ๋จ์ด๋ฅผ ์ฝ์ ์ ์์.
// antatica ์
๋ ฅ์ด ์ต์ํ์ ๋จ์ด๋ฐฐ์ด๋ฆฌ๊ณ
// k๊ฐ 5 ๋ฏธ๋ง์ด๋ฉด 0์ถ๋ ฅ ๋.
// b x d e f g h j k
int n, k;
cin >> n >> k;
int arr[26] = { 0, };
if (k < 5)
{
cout << 0;
return 0;
}
else
{
vector<string> word(n);
for (int i = 0; i < n; ++i)
{
cin >> word[i];
}
// a n t i c ๋ฅผ ํ๋ณดํ ์ํ์์
// 21 ๊ฐ ์ค์์ ์กฐํฉ์ ๋๋ฆฌ๊ณ ์ถ์.
// b, d , e, f, g, h, j, k ,l ,m , o, p,
// q, r, s, u ,v, w, x, y ,z
// ์ด๋ป๊ฒ ํ ๊ฑฐ๋๋ฉด ๋ฒกํฐ์ ๋ฃ๊ณ ,
// next_permutation ๋๋ฆฌ๋ฉด์
// k - 5 ๋งํผ์ for๋ฌธ์์ ๊ฐ์ฅ ์์ ์๋ ๊ฑธ๋ก
vector<char> c = { 'b', 'd' ,
'e', 'f', 'g', 'h', 'j', 'k' ,'l'
,'m' , 'o', 'p', 'q', 'r', 's', 'u'
,'v', 'w', 'x', 'y' ,'z' };
sort(c.begin(), c.end());
int cnt = k - 5;
//unordered_map<char, bool> check;
//check['a'] = true;
//check['n'] = true;
//check['t'] = true;
//check['i'] = true;
//check['c'] = true;
vector<bool> check(26, false);
check['a' - 'a'] = true;
check['n' - 'a'] = true;
check['t' - 'a'] = true;
check['i' - 'a'] = true;
check['c' - 'a'] = true;
int res = 0;
do
{
for (int i = 0; i < cnt; ++i)
{
check[c[i] - 'a'] = true;
}
int ccnt = 0;
// ๋จ์ด ์ ์ฒด ๋๋ฆฌ๊ธฐ.
for (int k = 0; k < word.size(); ++k)
{
bool br = false;
// ๋จ์ด ํ๊ธ์์ฉ ํ์ธํ๊ธฐ.
for (int l = 0; l < word[k].size(); ++l)
{
if (check[word[k][l] - 'a'] == false)
{
br = true;
break;
}
}
if (br == false)
{
++ccnt;
}
}
for (int i = 0; i < cnt; ++i)
{
// ์๋ณต.
check[c[i] - 'a'] = false;
}
res = max(res, ccnt);
} while (next_permutation(c.begin(), c.end()));
cout << res << endl;
}
}
http://boj.kr/223b0a3a54894c7cbd71ab6e56552732
1) ์ผ๋จ์ ์ฝ๊ฒ ์๊ฐํด์ ์ ๊ทผํ์.
2) ์๊ฐ ๋ณต์ก๋ ๊ฑธ๋ฆฌ๋ฉด, ํ์ดํธ ํ๊ฒ ์ ๊ทผํ๊ณ .
-> ๋๋์ .
: ๋๋ฌด ์ด๋ ต๊ฒ ์๊ฐํ์.
๊ทธ๋ฅ a n t i c ์ ์ธํ๊ณ 26 - 5 ์ค์์ k - 5 ๋งํผ ๋ค ๋๋ฆฐ ๋ค์์
string ๋ฒกํฐ์ ํ์ธํ๋ ์์ผ๋ก ํ์.
3) ์กฐํฉ ์์์ ์ฒดํฌ ๋ณ์ ํ์ธํ๋ ค๊ณ ๋ 26๊ฐ ๋๋ฆฌ๋ฉด์ ํ์ธํ๋๋ฐ,
์ด๋ฌ์ง ๋ง๊ณ , ์ด๋ฐ์์ผ๋ก ํ์ธํ์.
๋ด์ฉ : ์ด๋ฏธ ๋ด๊ฐ ๋ถ์ฒดํฌ ํ์๋ฅผ ํ์ผ๋ฏ๋ก,
ํด๋น rc , hello, car ์ ๋ํ ๋ถ๋ณ์๊ฐ true์ธ์ง ํ์ธ๋ง ํ๋ฉด ๋จ!
๊ฐ์ ๋ ์ฝ๋
์ข์ง ๋ชปํ , ์๊ฐ ๋ณต์ก๋ ์ฆ๊ฐํ๋ ์ฝ๋
http://boj.kr/30cc1e4a3ba64679a68e2c5474d5e09f
๋ฌธ์ ์์ 8๊ณผ ๋์ผํ ์ ์๋ค๊ณ ํ๋ค. ์ฆ
antatica ๊ฐ์ด๋ฐ์ ์๋ฌด๊ฒ๋ ์๋ค์ด ์ฌ์ ์๋ค๋ ์๋ฆฌ์.
๊ทผ๋ฐ ๋๋ ์๊ณ ์์์ง๋ง,, ํ ๋ถ๋ถ์ ์๋ชป ์์ฑํ์.
-์๋ชป ์์ฑํ ๋ถ๋ถ
-antic ์ด 5๊ฐ ์ด๋ฏ๋ก, k - 5 < 0 ์ผ๋ก ํด์ผํจ.
์๋ฌด๊ฒ๋ ์๋ค์ด์ค๋ฉด antatica ์ฆ 5๊ฐ๊ฐ ๋ชจ๋ ์ฐ์๋ค๋ ๊ฒ์ด๋ฏ๋ก...
: ์กฐํฉ์ผ๋ก ํ๋ ค๊ณ ํ๋๋ฐ ๋ณต์กํจ...
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#include <map>
// 1062๋ฒ. ๊ฐ๋ฅด์นจ.
// 19:55 ~
int n, k;
bool ccnt[26];
//๋งต์ผ๋ก ์ฒ๋ฆฌํ๋๊ฒ ๋น ๋ฅผ ๋ฏํ๋ฐ?
vector<char>temp;
map<char, bool>ttemp;
int result = -1;
void combi(vector<string>&v , vector<char>& word , int start)
{
if (ttemp.size() == k)
{
// ์ฌ๊ธฐ์ v์ ๋น๊ต ์ฒ๋ฆฌํ์.
bool ccheck = false;
int cnt = 0;
for (int a = 0; a < v.size(); ++a)
{
int ssize = v[a].size();
for (auto iter : v[a])
{
if (ttemp.find(iter) == ttemp.end())
{
ccheck = true;
break;
}
}
if (ccheck == false)
++cnt;
}
result = max(result, cnt);
return;
}
for (int i = start; i < word.size(); ++i)
{
ttemp.insert(make_pair(word[i], true));
//temp.push_back(word[i]);
combi(v, word, i + 1);
//temp.pop_back();
ttemp.erase(word[i]);
}
}
int main()
{
cin >> n >> k;
// 6๊ฐ์ ๊ธ์๋ฅผ ๊ฐ๋ฅด์นจ.
// anta , tica
// a n t i c -> antatica๋ก๋ง 5๊ฐ๊ฐ ์์๋๋ฏ๋ก
// k = 6 - 5 : 1๊ฐ์ ๊ธ์๋ง ๋ฐฐ์ธ์ ์์.
// c๋ฅผ ๋ฐฐ์ฐ๋ฉด.
// rc, car ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํจ.
// a n t i c ๋ฅผ ์ ์ธํ ๊ธ์๋ค ์ค์์ . ์ฆ, 26 - 5๊ฐ์ ๊ธ์์ค์์
// k - 5๋งํผ์ ์กฐํฉ์ ๋๋ ค์
// ์ฒดํฌ ๋ณ์์์ ๋ฝ์ ๊ธ์์ ์์๊ฐ ์ ์ด์ฉํด true๋ก ์ค์ ํ๊ณ ,
// ๋ชจ๋๋ค true ์ด๋ฉด ์นด์ดํ
์ ์งํ
// ์ด๋ ๊ฒ ์งํํ๋ฉด์ ์นด์ดํ
์ ์ต๋๊ฐ์ ์ถ์ถํ์.
ccnt['a' - 'a'] = true;
ccnt['n' - 'a'] = true;
ccnt['t' - 'a'] = true;
ccnt['i' - 'a'] = true;
ccnt['c' - 'a'] = true;
vector<string>v(n);
for (int i = 0; i < n; ++i)
{
cin >> v[i];
// ์์ ์์นํจ anta , ๋ค์ ์์นํ tica๋ฅผ ๋บ.
string s1 = v[i].substr(4 , v[i].length() - 8);
//cout << "output" << endl;
//cout << s1 << endl;
v[i] = s1;
for (auto iter : s1)
{
ccnt[iter - 'a'] = true;
}
//cout << v[i] << endl;
}
vector<char>ww;
for (int i = 0; i < 26; ++i)
{
if (ccnt[i] == true && i != 'a' - 'a'
&& i != 'n' - 'a' && i != 't' - 'a'
&& i != 'i' - 'a' && i != 'c' - 'a')
{
char c = i + 'a';
ww.push_back(c);
cout << c << endl;
}
}
// a n t i c
if (k - 5 <= 0)
return 0;
k -= 5;
// ww ์ ๋ค์ด์๋ ์์๋ค ์ค์์ num๋ฅผ ๊บผ๋ด ๋๋ฆฌ๋ฉด์
// ๋ชจ๋ ์ผ์นํ๋ฉด ok.
// rc -> r
// hello -> h e l o
// car -> r
// ์ฌ๊ธฐ ์๋ ๋จ์ด๋ค๋ก ๋ฒกํฐ์ ๋ฃ์ ๋ค์์
// ์กฐํฉ ๋๋ฆฌ๋ฉด์ ์ต๋๊ฐ ํ์ธํ๊ธฐ
combi(v, ww, 0);
cout << result;
}