삐까냥의 파도타기

2115. 벌꿀채취 본문

코딩/SW Expert Academy

2115. 벌꿀채취

금손형아 2018. 4. 14. 00:09

2115. 벌꿀채취


https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V4A46AdIDFAWu



이게 55프로의 정답률.


이것저것 섞여있어서 


문제를 보자마자 머리아팠어요.





2018년 4월 14일 - 다듬지 않은 코드 (소요시간 45분)


import java.util.Scanner;


public class Q2115 {


static int mapSize, size, maxValue, maxResult;

static int[][] map;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int testCase = sc.nextInt();

for (int i = 1; i <= testCase; i++) {

maxResult = 0;

mapSize = sc.nextInt();

size = sc.nextInt();

maxValue = sc.nextInt();

map = new int[mapSize][mapSize];

for (int j = 0; j < mapSize; j++) {

for (int k = 0; k < mapSize; k++) {

map[j][k] = sc.nextInt();

}

}

for (int j = 0; j < mapSize; j++) {

for (int k = 0; k < mapSize-(size-1); k++) {

selectSecond(j, k);

}

}

System.out.println("#" + i + " " + maxResult);

}

}

static void selectSecond(int firstY, int firstX) {

for (int j = firstY; j < mapSize; j++) {

int k = 0;

if (j == firstY) {

k = firstX+size;

}

for (; k < mapSize-(size-1); k++) {

calResult(firstY, firstX, j, k);

}

}

}

static int tempMax;

static int[] tempFirst;

static void calResult (int firstY, int firstX, int secondY, int secondX) {

// System.out.print("(" + firstY + ", " + firstX + ") (" + secondY + ", " + secondX + ")  ");

tempFirst = new int[size];

for (int i = firstX; i < firstX+size; i++) {

tempFirst[i-firstX] = map[firstY][i];

}

tempMax = 0;

for (int i = 0; i < size; i++) {

if (tempFirst[i] <= maxValue) {

check(i, maxValue-tempFirst[i], tempFirst[i]*tempFirst[i]);

}

}

int result = tempMax;

for (int i = secondX; i < secondX+size; i++) {

tempFirst[i-secondX] = map[secondY][i];

}

tempMax = 0;

for (int i = 0; i < size; i++) {

if (tempFirst[i] <= maxValue) {

check(i, maxValue-tempFirst[i], tempFirst[i]*tempFirst[i]);

}

}

result += tempMax;

// System.out.println(result);

if (maxResult < result) {

maxResult = result;

}

// System.out.println(maxResult);

}

static void check(int now, int remainValue, int nowValue) {

if (tempMax < nowValue) {

tempMax = nowValue;

}

for (int i = now+1; i < size; i++) {

if (tempFirst[i] <= remainValue) {

check(i, remainValue-tempFirst[i], nowValue + (tempFirst[i]*tempFirst[i]));

}

}

}

}

 


'코딩 > SW Expert Academy' 카테고리의 다른 글

1952. 수영장  (0) 2018.04.15
1953. 탈주범 검거  (0) 2018.04.15
2383. 점심 식사시간  (0) 2018.04.13
2382. 미생물 격리  (0) 2018.04.13
1949. 등산로 조성  (0) 2018.04.13