본문 바로가기

알고리즘16

인덱스 트리 (Indexed Tree) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { /* * 구간 합 구하기 * https://www.acmicpc.net/problem/2042 */ public static void main(String[] args) throws IOException {.. 2018. 7. 17.
플로이드 워셜 (Floyd Warshall) public class Floyd_Warshall { static final int _M_size_ = 100; // max number of vertices static final int _INTMAX_ = 1000000000; // infinite static int AdjMatrix[][] = new int[_M_size_][_M_size_]; // Adjacent matrix static int dist[][] = new int [_M_size_][_M_size_]; // Shortest distance matrix static void floyd_warshall(int V) { for(int i = 1 ; i 2018. 7. 17.
다익스트라 (Dijkstra) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main_1753 { /* * 최단경로 * https://www.acmicpc.net/problem/1753 * Dijkstra */ .. 2018. 7. 17.
DFS (Stack) package graph; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.Stack; import java.util.StringTokenizer; public class DFS_stack { /* * DFS, BFS */ public static void main(String[] args.. 2018. 7. 17.