-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51ae761
commit 8655394
Showing
1 changed file
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
// Authored by : BaaaaaaaaaaarkingDog | ||
// Co-authored by : - | ||
// http://boj.kr/**************** | ||
// http://boj.kr/2532d97629b04d7c86f15db6bee08772 | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main(void){ | ||
int n, m; | ||
long long state[10]; | ||
|
||
int bit_cnt(long long x){ | ||
int ret = 0; | ||
for(int i = 0; i < m; i++){ | ||
ret += (x >> i) & 1; | ||
} | ||
return ret; | ||
} | ||
|
||
int main(){ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
|
||
} | ||
cin >> n >> m; | ||
for(int i = 0; i < n; i++){ | ||
string name, tmp; // name은 사실 의미없음 | ||
cin >> name >> tmp; | ||
for(int j = m-1; j >= 0; j--){ | ||
state[i] = (state[i] << 1) | (tmp[j] == 'Y'); | ||
} | ||
} | ||
|
||
pair<int, int> ans = {0, -1}; // {연주할 수 있는 곡의 수, 필요한 기타의 수} | ||
for(int tmp = 0; tmp < (1 << n); tmp++){ | ||
long long comb = 0; // 조합한 결과 | ||
for(int i = 0; i < m; i++){ | ||
if((tmp & (1LL << i)) == 0) | ||
continue; | ||
comb |= state[i]; | ||
} | ||
int song_num = bit_cnt(comb); | ||
int guitar_num = bit_cnt(tmp); | ||
if(ans.first < song_num) // 1. 연주할 수 있는 곡의 수가 더 많을 경우 | ||
ans = {song_num, guitar_num}; | ||
// 2. 연주할 수 있는 곡의 수는 같은데 필요한 기타의 수가 더 적을 경우 | ||
else if(ans.first == song_num && ans.second > guitar_num) | ||
ans = {song_num, guitar_num}; | ||
} | ||
cout << ans.second << '\n'; | ||
} |