-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1497.cpp
58 lines (54 loc) · 1.14 KB
/
1497.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
int n, m;
int song_data[10][50];
int ans_song = 0;
int ans_guitar = 0;
int check_list[50];
void bt(int start, int guitars) {
int now_songs = 0;
for (int j = 0; j < m; j++) {
if (check_list[j] > 0)
now_songs++;
}
if (now_songs > ans_song) {
ans_song = now_songs;
ans_guitar = guitars;
}
else if (now_songs == ans_song)
ans_guitar = min(ans_guitar, guitars);
for (int i = start + 1; i < n; i++) {
for (int j = 0; j < m; j++)
check_list[j] += song_data[i][j];
bt(i, guitars + 1);
for (int j = 0; j < m; j++)
check_list[j] -= song_data[i][j];
}
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string songname;
char yn;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> songname;
yn = cin.get();
for (int j = 0; j < m; j++) {
yn = cin.get();
if (yn == 'Y')
song_data[i][j] = 1;
else
song_data[i][j] = 0;
}
}
for (int j = 0; j < m; j++)
check_list[j] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
check_list[j] = song_data[i][j];
bt(i, 1);
}
(ans_guitar > 0) ? cout << ans_guitar : cout << -1;
}