회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
틀렸습니다... 뜨는데... 뭐가 잘못된건지 모르겠어요ㅜㅜ 한번만 봐주세요!!
1937번 - 욕심쟁이 판다
ksm9660
6년 전
0
BFS로 풀었어요..!!
#include <iostream> #include <fstream> #define MAX 501 using namespace std; typedef struct point { int r; int c; }P; int change_r[4] = { 0, -1, 0, 1 }; // 서, 북, 동, 남 순서 int change_c[4] = { -1, 0, 1, 0 }; int M, N; int map[MAX][MAX]; int dp[MAX][MAX] = { 0, }; int result = -1; P cur; int main() { ifstream fin; fin.open("욕심쟁이판다.txt"); fin >> N; //cin >>N; // #1: 입력 for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { //cin >> map[r][c]; fin >> map[r][c]; } } // #2: 계산 for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { P queue[100000]; int top = 0, bottom = 0; if (dp[r][c] == 0) { dp[r][c] = 1; queue[top] = { r, c }; top++; while (top > bottom) { cur = queue[bottom]; bottom++; for (int i = 0; i < 4; i++) { int row = cur.r + change_r[i]; int col = cur.c + change_c[i]; if (0 <= row && row <= N - 1 && 0 <= col && col <= N - 1 && map[cur.r][cur.c] < map[row][col] && dp[row][col] < dp[cur.r][cur.c] + 1) { dp[row][col] = dp[cur.r][cur.c] + 1; queue[top] = { row, col }; top++; } } } } } } for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { if (dp[r][c] > result) { result = dp[r][c]; } } } cout << result << endl; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
ksm9660 6년 전
BFS로 풀었어요..!!