11 29 2019學習記錄

2022-04-11 05:41:19 字數 1290 閱讀 2304

昨天看了一下廣度意義上的深度遍歷(dfs) 今天接著學到了廣度意義上的廣度優先遍歷(bfs)

這種廣度優先遍歷在實際意義上與圖中深度遍歷優先是類似的

dfs隱含的利用了棧(遞迴),bfs則是利用了佇列

這道題便是利用bfs的一道題 每次從棧中彈出元素 都會把它上下左右四個方向檢測將未訪問可達的元素入棧

1 #include2 #include3

using

namespace

std;

4#define inf 1000000

5#define max_n 100

6#define max_m 100

7 typedef pairp;

8char

maze[max_n][max_m];

9int

n, m;

10int

sx, sy;

11int

ex, ey;

12int

dist[max_n][max_n];

13int dx[4] = ;

14int dy[4] = ;

15int

bfs()35}

36}37}

38return

dist[ex][ey];39}

40void

solve()

44//

讀入資料

45int

main()

4655

56/*

5710 10

58#s######.#

59......#..#

60.#.##.##.#

61.#........

62##.##.####

63....#....#

64.#######.#

65....#.....

66.####.###.

67....#...g#

680 1

699 8

70*/

view code

dfs和bfs都是屬於列舉的方法

接著書上提到了貪心

貪心是遵循某種規則 不斷貪心地選取當前最優策略地想法

書上給了幾道很好地例題來體現 硬幣問題 區間問題 字典序最小問題

再接著講到了動態規劃(dynamic programming)

提到了揹包問題 利用記憶化搜尋 將已經處理過的情況記錄

mysql學習記錄 MySQL學習記錄 2

in 子查詢 select from student where id in 1,2 not in 不在其中 select from student where id not in 1,2 is null 是空 select from student where age is null is not...

java學習記錄

陣列雖然是引用資料型別,但它不是類 所以數字中沒有length 方法 只有length屬性。string型別 是乙個類 jdk中已經封裝好的類,是個final類,你可以去查api 類就有屬性和方法但是 string類中沒有length屬性,只有length 方法 1。陣列雖然是引用資料型別,但它不是...

Linux 學習記錄

1.linux 拷貝隱藏檔案 進入當前需要拷貝的目錄,即源目錄 假如 source 拷貝到 centos5.3 cd source tar cf cd centos5.3 tar xvf 或者 cp r centos5.3 2.linux 下新增postgresql 使用者 進入 postgresq...