Skip to content

Commit 6ee9ed9

Browse files
committed
update
1 parent fb5df37 commit 6ee9ed9

File tree

7 files changed

+90
-9
lines changed

7 files changed

+90
-9
lines changed

lecture1/lecture1/ex036.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ using namespace chrono;
1010

1111
void ex036() {
1212
vector<int> a{ 7, 11, 5, 6, 10, 9 };
13-
int j;
13+
1414
for (int i = 1; i < a.size(); i++) {
1515
int tmp = a[i];
16-
for (j = i - 1; j >= 0; j--) {
16+
int j;
17+
for (j = i - 1; j >= 0; j--) { // 역순회
1718
if (a[j] > tmp) {
1819
a[j + 1] = a[j]; // 뒤로 이동
1920
}
2021
else {
2122
break;
2223
}
2324
}
24-
a[j + 1] = tmp; // 현재까지 정렬된 숫자들 바로 뒤에 삽입
25+
a[j + 1] = tmp; // 현재까지 정렬된 숫자들 앞에 삽입
2526
}
27+
// 결과 출력
2628
for (int i = 0; i < a.size(); i++) {
2729
cout << a[i] << ' ';
2830
}

lecture1/lecture1/ex042.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void sort_insert2(vector<int> & vec) {
2323
void ex042() {
2424
int M = 32;
2525
vector<int> a{ 23, 87, 65, 12, 57, 32, 99, 81 };
26+
2627
sort_insert2(a); // ¿À¸¥Â÷¼ø Á¤·Ä
2728
int lt = 0;
2829
int rt = a.size() - 1;

lecture1/lecture1/ex058.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ void ex058() {
4343
dfs_mid(1);
4444
cout << endl;
4545
dfs_post(1);
46-
4746
}
4847

4948
//int main() {

lecture1/lecture1/ex066.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,45 @@
55
using namespace std;
66

77
// 경로 탐색(DFS : 인접리스트 방법)
8+
static int cnt = 0;
9+
static const int n = 5;
10+
static vector<int> ch(n + 1);
11+
static vector<vector<int>> map(n + 1);
12+
13+
void dfs(int v) {
14+
if (v == n) {
15+
cnt++;
16+
}
17+
else {
18+
for (int i = 0; i < map[v].size(); i++) {
19+
if (ch[map[v][i]] == 0) {
20+
ch[map[v][i]] = 1;
21+
dfs(map[v][i]);
22+
ch[map[v][i]] = 0;
23+
}
24+
}
25+
}
26+
}
827

928
void ex066() {
29+
int v = 9;
30+
vector<vector<int>> inputs{ {1, 2}, {1, 3}, {1, 4}, {2, 1}, {2, 3}, {2, 5}, {3, 4}, {4, 2}, {4, 5} };
31+
for (auto itr = inputs.begin(); itr != inputs.end(); ++itr) {
32+
map[((*itr)[0])].push_back((*itr)[1]);
33+
}
34+
for (int i = 0; i < map.size(); i++) {
35+
for (int j = 0; j < map[i].size(); j++) {
36+
cout << map[i][j] << " ";
37+
}cout << endl;
38+
}
39+
ch[1] = 1;
40+
dfs(1);
41+
cout << cnt << endl;
1042

1143
}
1244

13-
int main() {
14-
ex066();
15-
cout << endl << "done!" << endl;
16-
}
17-
// 8
45+
//int main() {
46+
// ex066();
47+
// cout << endl << "done!" << endl;
48+
//}
49+
// 6

lecture1/lecture1/ex067.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
#include <stack>
5+
using namespace std;
6+
7+
// 경로 탐색(DFS : 인접리스트 방법)
8+
static int cost = 2147000000;
9+
static const int n = 5;
10+
static vector<int> ch(n+1);
11+
static vector<vector<int>> map(n+1 , vector<int>(n+1, 0));
12+
13+
static void dfs(int v, int sum) {
14+
if (v == 5) {
15+
if (cost > sum)
16+
cost = sum;
17+
}
18+
else {
19+
for (int i = 1; i < map[v].size(); i++) {
20+
if (ch[i] == 0 && map[v][i] != 0) {
21+
ch[i] = 1;
22+
dfs(i, sum + map[v][i]);
23+
ch[i] = 0;
24+
}
25+
}
26+
}
27+
}
28+
29+
void ex067() {
30+
vector<vector<int>> inputs{ {1, 2, 12}, {1, 3, 6}, {1, 4, 10}, {2, 3, 2}, {2, 5, 2}, {3, 4, 3}, {4, 2, 2}, {4, 5, 5} };
31+
for (int i = 0; i < inputs.size(); i++) {
32+
map[inputs[i][0]][inputs[i][1]] = inputs[i][2];
33+
}
34+
ch[1] = 1;
35+
dfs(1, 0);
36+
cout << cost << endl;
37+
}
38+
39+
//int main() {
40+
// ex067();
41+
// cout << endl << "done!" << endl;
42+
//}
43+
// 13

lecture1/lecture1/lecture1.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<ClCompile Include="ex064.cpp" />
190190
<ClCompile Include="ex065.cpp" />
191191
<ClCompile Include="ex066.cpp" />
192+
<ClCompile Include="ex067.cpp" />
192193
</ItemGroup>
193194
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
194195
<ImportGroup Label="ExtensionTargets">

lecture1/lecture1/lecture1.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,8 @@
213213
<ClCompile Include="ex066.cpp">
214214
<Filter>소스 파일</Filter>
215215
</ClCompile>
216+
<ClCompile Include="ex067.cpp">
217+
<Filter>소스 파일</Filter>
218+
</ClCompile>
216219
</ItemGroup>
217220
</Project>

0 commit comments

Comments
 (0)