-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1029.cpp
More file actions
36 lines (26 loc) · 697 Bytes
/
Copy path1029.cpp
File metadata and controls
36 lines (26 loc) · 697 Bytes
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
#include <iostream>
#include <algorithm>
using namespace std;
int N;
char arr[15][15];
int dp[1024 * 32][15];
int DFS(int cur, int price, int bits) {
bits = (bits | (1 << cur));
if (dp[bits][cur]) return dp[bits][cur];
for (int next = 1; next < N; next++) {
if ((bits & (1 << next)) == 0 && arr[cur][next] >= price)
dp[bits][cur] = max(dp[bits][cur], DFS(next, arr[cur][next], bits) + 1);
}
return dp[bits][cur];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
cin >> arr[i][j];
}
cout << DFS(0, 0, 0) + 1;
return 0;
}