1+ #include < cstring>
2+ #include < iostream>
3+ #include < vector>
4+ #include < cstring>
5+
6+ using namespace std ;
7+
8+ int N;
9+ // 미술가들
10+ vector<vector<int >> a;
11+
12+ int cache[1 <<15 ][10 ][15 ];
13+ // 여기서 최적화해야할 부분은
14+ // 이미 산 사람에 대한 배열이다.
15+ // dp에서 배열 그대로를 넣게 된다면 dp를 할 수 없다.
16+ // 어차피 false, true이면 0 , 1 이기 때문에 한 줄의 비트열로 만들 수 있다.
17+ // 1101 >> 13으로 변환 가능
18+ int func (int selled, int nowP, int from){
19+ // 기저사례 : 만약에 다 팔았다면 종료 TOOD
20+ if (selled == (1 <<N)) return 0 ;
21+
22+
23+
24+ int & ret = cache[selled][nowP][from];
25+
26+ if (ret!=-1 ) return ret;
27+
28+ ret = 1 ;
29+ // 정수로 변환된 것을 다시 배열로 돌려본다. TODO
30+ // from은 필요가 없는가?
31+ // to 팔아야할 사람이 nowP
32+ // 어떤 from , to든 상관없이 팔기만 하면되는거 아닌가?
33+ for (int to=0 ; to < N; to++){
34+ // 팔렸다면
35+ if (selled & (1 << to)) continue ;
36+ // int from = -1;
37+ // // 고쳐야한다
38+ // // 자기 자신 찾기
39+ // for(int i=0; i < N; i++){
40+ // if(a[to][i] == 0) from = i;
41+ // }
42+
43+ // cout << "to : " << to << endl;
44+ // cout << from << endl;
45+ // 팔리지 않은 사람에게 현재
46+ // 더 크다고 생각한다면
47+ if ((a[from][to] >=nowP)){
48+ ret = max (ret, 1 + func (selled + (1 << to) ,a[from][to],to));
49+ }
50+ }
51+
52+ return ret;
53+
54+ }
55+
56+ int main (void ){
57+ ios::sync_with_stdio (0 );
58+ cin.tie (0 );
59+
60+ cin >> N;
61+ // 배열 N 크기로 초기화
62+ a.assign (N, vector<int >(N,-1 ));
63+
64+
65+
66+ // N * N 크기의 배열로 값을 받아옴
67+ for (int i = 0 ; i < N; i++) {
68+ string line;
69+ cin >> line;
70+ for (int j = 0 ; j < N; j++) {
71+ a[i][j] = line[j] - ' 0' ;
72+ }
73+ }
74+
75+
76+ memset (cache, -1 , sizeof (cache));
77+
78+
79+ cout << func (1 ,0 ,0 ) << endl;
80+
81+ return 0 ;
82+ }
0 commit comments