SHARE
TWEET

Untitled

a guest Apr 18th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 토끼가 정보섬에 올라온 이유
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdbool.h>
  6. #include <math.h>
  7. #include <limits.h>
  8. #define MAX 1002
  9.  
  10. int main(){
  11.  
  12.     int N, M, dy, ans = -1, Max = 0;
  13.     char map[MAX][MAX] = {0,};
  14.     int dp[MAX][MAX] = {0,};
  15.  
  16.     memset( map, 0, sizeof(map) );
  17.     memset( dp, -1, sizeof(dp) );
  18.     scanf("%d %d", &N, &M);
  19.     fgetc(stdin);
  20.     for( int i=1; i<=N; i++ ){
  21.         for( int j=1; j<=M; j++ ){
  22.             scanf("%c", &map[i][j]);
  23.         }
  24.         fgetc(stdin);
  25.     }
  26.  
  27.     for( int i=1; i<=N; i++ ){
  28.         for( int j=1; j<=M; j++ ){
  29.             if( map[i][j] == 'R' ){
  30.                 dp[i][j] = 0;
  31.                 dy = j;
  32.             }
  33.         }
  34.     }
  35.  
  36.     for( int j=dy+1; j<=M; j++ ){
  37.         for( int i=1; i<=N; i++ ){
  38.             if( map[i][j] != '#' ){
  39.                 Max = dp[i][j-1]>dp[i-1][j-1]?dp[i][j-1]:dp[i-1][j-1];
  40.                 Max = Max>dp[i+1][j-1]?Max:dp[i+1][j-1];
  41.                 dp[i][j] = Max;
  42.                 if( map[i][j] == 'C' && dp[i][j] != -1 ){
  43.                     dp[i][j]++;
  44.                 }
  45.                 if( map[i][j] == 'O' ){
  46.                     ans = ans>dp[i][j]?ans:dp[i][j];
  47.                 }
  48.             }
  49.         }
  50.     }
  51.    
  52.     printf("%d", ans);
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top