Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Value too long for column
- pytest
- k8s #kubernetes #쿠버네티스
- 겨울 부산
- 코루틴 컨텍스트
- terminal
- table not found
- JanusWebRTCServer
- taint
- PytestPluginManager
- 티스토리챌린지
- 오블완
- 개성국밥
- python
- JanusWebRTC
- Spring Batch
- 달인막창
- VARCHAR (1)
- preemption #
- tolerated
- 코루틴 빌더
- PersistenceContext
- JanusWebRTCGateway
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- JanusGateway
- vfr video
- 자원부족
- mp4fpsmod
- 깡돼후
- kotlin
Archives
너와 나의 스토리
1949. [모의 SW 역량테스트] 등산로 조성 본문
반응형
문제: https://swexpertacademy.com/main/solvingProblem/solvingProblem.do
소스코드:
#include <iostream>
#include <queue>
#include <vector>
#include <string.h>
#include <algorithm>
#include <deque>
using namespace std;
int tc, n,mi, dist[51][51], arr[51][51],res;
typedef pair<int, int> P;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
vector<P> adj;
queue<P> q;
int dfs(int curx,int cury) {
if (dist[curx][cury]) return dist[curx][cury];
dist[curx][cury] = 1;
for (int i = 0; i < 4; i++) {
int x = curx + dx[i];
int y = cury + dy[i];
if (x < 0 || x >= n || y < 0 || y >= n || arr[curx][cury] <= arr[x][y]) continue;
dist[curx][cury]=max(dist[curx][cury],dfs(x, y)+1);
}
return dist[curx][cury];
}
void func() {
for (int z = 0; z < adj.size(); z++) {
memset(dist, 0, sizeof(dist));
res = max(res, dfs(adj[z].first, adj[z].second));
}
for (int k = 1; k <= mi; k++) {
memset(dist, 0, sizeof(dist));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] -= k;
for (int z = 0; z < adj.size(); z++) {
memset(dist, 0, sizeof(dist));
res=max(res,dfs(adj[z].first, adj[z].second));
}
arr[i][j] += k;
}
}
}
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
cin >> tc;
for (int i = 1; i <= tc; i++) {
cin >> n>>mi;
res = 1;
adj.clear();
int tmp = 0;
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
cin >> arr[j][k];
if (tmp < arr[j][k]) {
tmp = arr[j][k];
}
}
}
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
if (arr[j][k]==tmp) {
adj.push_back({ j,k });
}
}
}
func();
cout <<"#"<<i<<" "<< res << '\n';
}
return 0;
}
반응형
'Algorithm > bfs, dfs' 카테고리의 다른 글
[BOJ] 16137 견우와 직녀 (0) | 2020.10.17 |
---|---|
[BOJ] 17244 아맞다우산 (0) | 2020.10.17 |
[BOJ] 1938 통나무 옮기기 (0) | 2020.06.02 |
[BOJ] 13565 침투 (0) | 2019.10.04 |
(BOJ) 3830 교수님은 기다리지 않는다 (0) | 2019.07.31 |
Comments