Submission #9795

# Submission time Handle Problem Language Result Execution time Memory
9795 2014-09-28T08:58:41 Z sior On grid (kriii2_O) C++
0 / 4
0 ms 2384 KB
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <utility>

using namespace std;

#define INF -987654321
#define CACHE -98765321

int cache[301][301];
int board[301][301];
int numOfX, numOfY;

int gridSum(int y1, int x1, int y2, int x2);
int generate(int y_here, int x_here/*현재 위치*/);



int main()
{

	cin >> numOfX >> numOfY;

	for (int i = 0; i < 301; i++)
	{
		for (int j = 0; j < 301; j++)
			cache[i][j] = CACHE;
	}
	for (int y = 0; y < numOfY; y++)
	{
		for (int x = 0; x < numOfX; x++)
		{
			cin >> board[y][x];
		}
	}

	for (int x = 1; x < numOfX; x++)
	{
		board[0][x] += board[0][x - 1];
	}
	for (int y = 1; y < numOfY; y++)
	{
		board[y][0] += board[y - 1][0];
		for (int x = 1; x < numOfX; x++)
		{
			board[y][x] += board[y][x - 1] + board[y - 1][x];
			board[y][x] -= board[y - 1][x - 1];
		}
	}

	cout << generate(0, 0) << endl;
	return 0;
}

int generate(int here_y, int here_x)
{
	/*
	if (here_y == numOfY-1 && here_x == numOfX-1)
		return gridSum(here_y, here_x, here_y, here_x);
	*/
	int &ret = cache[here_y][here_x];

	if (ret != CACHE) return ret;

	if (here_y == numOfY &&
		here_x == numOfX)
		return gridSum(here_y, here_x, numOfY - 1, numOfX - 1);

	if (here_y == numOfY ||
		here_x == numOfX)
		return -987654321;

	ret = gridSum(here_y, here_x, numOfY - 1, numOfX - 1);

	for (int y = here_y; y < numOfY-1; y++)
	{
		for (int x = here_x; x < numOfX-1; x++)
		{
			int y_next = y + 1;
			int x_next = x + 1;

			int a = gridSum(here_y, here_x, y, x);
			int b = generate(y_next, x_next);
			ret = max(ret, gridSum(here_y, here_x, y, x) + generate(y_next, x_next));
		}
	}

	return ret;

}
int gridSum(int y1, int x1, int y2, int x2)
{
	int ret = board[y2][x2];
	if (y1 > 0) ret -= board[y1 - 1][x2];
	if (x1 > 0) ret -= board[y2][x1 - 1];
	if (y1 > 0 && x1 > 0) ret += board[y1 - 1][x1 - 1];
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2384 KB Output is correct
2 Incorrect 0 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -