File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ // http://boj.kr/2532d97629b04d7c86f15db6bee08772
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+
5
+ int n, m;
6
+ long long state[10 ];
7
+
8
+ int bit_cnt (long long x){
9
+ int ret = 0 ;
10
+ for (int i = 0 ; i < m; i++){
11
+ ret += (x >> i) & 1 ;
12
+ }
13
+ return ret;
14
+ }
15
+
16
+ int main (){
17
+ ios::sync_with_stdio (0 );
18
+ cin.tie (0 );
19
+
20
+ cin >> n >> m;
21
+ for (int i = 0 ; i < n; i++){
22
+ string name, tmp; // name은 사실 의미없음
23
+ cin >> name >> tmp;
24
+ <
B1A7
span class="pl-k">for(int j = m-1 ; j >= 0 ; j--){
25
+ state[i] = (state[i] << 1 ) | (tmp[j] == ' Y' );
26
+ }
27
+ }
28
+
29
+ pair<int , int > ans = {0 , -1 }; // {연주할 수 있는 곡의 수, 필요한 기타의 수}
30
+ for (int tmp = 0 ; tmp < (1 << n); tmp++){
31
+ long long comb = 0 ; // 조합한 결과
32
+ for (int i = 0 ; i < m; i++){
33
+ if ((tmp & (1LL << i)) == 0 )
34
+ continue ;
35
+ comb |= state[i];
36
+ }
37
+ int song_num = bit_cnt (comb);
38
+ int guitar_num = bit_cnt (tmp);
39
+ if (ans.first < song_num) // 1. 연주할 수 있는 곡의 수가 더 많을 경우
40
+ ans = {song_num, guitar_num};
41
+ // 2. 연주할 수 있는 곡의 수는 같은데 필요한 기타의 수가 더 적을 경우
42
+ else if (ans.first == song_num && ans.second > guitar_num)
43
+ ans = {song_num, guitar_num};
44
+ }
45
+ cout << ans.second << ' \n ' ;
46
+ }
You can’t perform that action at this time.
0 commit comments