일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 가끔은 말로
- 이분 탐색
- 가끔은_말로
- Overfitting
- 알고리즘
- lazy propagation
- object detection
- 2023
- tensorflow
- back propagation
- 우선 순위 큐
- BFS
- NEXT
- 조합론
- 너비 우선 탐색
- 세그먼트 트리
- 회고록
- dfs
- DP
- 분할 정복
- c++
- 미래는_현재와_과거로
- 다익스트라
- 자바스크립트
- 백트래킹
- 크루스칼
- dropout
- pytorch
- 플로이드 와샬
- 문자열
Archives
- Today
- Total
Doby's Lab
백준 6185번: Clear And Present Danger (C++) 본문
https://www.acmicpc.net/problem/6185
6185번: Clear And Present Danger
There are 3 islands and the treasure map requires Farmer John to visit a sequence of 4 islands in order: island 1, island 2, island 1 again, and finally island 3. The danger ratings of the paths are given: the paths (1, 2); (2, 3); (3, 1) and the reverse p
www.acmicpc.net
Level: Gold V
Solved By: Floyd Warshall
특정 sequence를 지나쳐야 하기에 이 정보들을 담아주었고, 모든 노드에 대한 N:N 최단 경로 정보가 필요했기 때문에 Floyd Warshall을 사용하여 풀었습니다.
#include <iostream>
#include <vector>
#define MAX 101
using namespace std;
int N, M;
vector<int> sequence;
int graph[MAX][MAX];
void floydWarshall(){
for(int k = 1; k <= N; k++){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
if(i == k || k == j) continue;
if(graph[i][k] + graph[k][j] < graph[i][j]){
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
}
int main(){
cin >> N >> M;
for(int i = 0; i < M; i++){
int v; cin >> v;
sequence.push_back(v);
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
cin >> graph[i][j];
}
}
floydWarshall();
int res = 0;
for(int i = 1; i < sequence.size(); i++){
res += graph[sequence[i - 1]][sequence[i]];
}
cout << res;
return 0;
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 26123번: 외계 침략자 윤이 (C++) (0) | 2022.11.27 |
---|---|
백준 26122번: 가장 긴 막대 자석 (C++) (0) | 2022.11.27 |
백준 17134번: 르모앙의 추측 (C++) (0) | 2022.11.23 |
백준 1417번: 국회의원 선거 (C++) (0) | 2022.11.21 |
백준 1057번: 토너먼트 (C++) (0) | 2022.11.20 |