TAILIEUCHUNG - ASP.NET 2.0 - PART 2

Tham khảo tài liệu ' - part 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 220 Appendix B Common Codes Routines F or Programming int n while cin n _ cout The Fibonacci number for n is fibo n n return 0 BFS DFS Maze Problem Input 8 8 . . . . . . . . . . . . . . . .s d. . include include include define N 100 define MAX MAXINT int mat N N Q N 3 cost N N front -1 rear -1 int m n sc sr p nr nc r c leaf i j res 10 10 int R 4 0 -1 int C 4 -1 0 0 1 1 0 void nQ int r int c int p Q rear 0 r Q rear 1 c Q rear 2 p void dQ int r int c int p r Q front 0 c Q front 1 p front void bfs int sr int sc int p nQ sr sc p do dQ r c p for int i 0 i 4 i 221 Appendix B Common Codes Routines F or Programming nr r R i nc c C i if mat nr nc 1 if cost nr nc cost r c 1 cost nr nc cost r c 1 nQ nr nc p while rear front leaf p void show for int i 0 i m i for int j 0 j n j if res i j printf X else printf printf n void dfs int leaf if Q leaf 2 -1 res Q leaf 0 Q leaf 1 1 return dfs Q leaf 2 res Q leaf 0 Q leaf 1 1 void main clrscr char ch freopen r stdin scanf d d m n getchar for i 0 i m i for j 0 j n j cost i j MAX scanf c ch if ch mat i j 0 else if ch . mat i j 1 else if ch s 222 Appendix B Common Codes Routines F or Programming mat i j 2 sc j sr i else mat i j 3 res i j 1 getchar bfs sr sc -1 dfs leaf show MinSum DFS QUEUE Input 5 6 3 4 1 2 8 6 6 1 8 2 7 4 5 9 3 9 9 5 8 4 1 3 2 6 3 7 2 1 2 3 Code include include include define N 100 define MAX MAXINT int mat N N M N N Q N 4 front -1 rear -1 int m n nc nr p s finalSum MAX leaf r c i void init for int i 0 i N i for int j 0 j N j M i j MAX mat i j 0 void nQ int r int c int p int s Q rear 0 r Q rear 1 c Q rear 2 p Q rear 3 s void dQ int r int c int p int s r Q front 0 c Q front 1 p front s Q front 3

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.