[ create a new paste ] login | about

Link: http://codepad.org/DpurkxnA    [ raw code | output | fork ]

hoaithu.melody - C++, pasted on Jun 25:
// SPOJ BYTESM2

#include <iostream>
#include <conio.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define maxN 100

int h, w;
int stones[maxN][maxN];

int main()
{
	freopen("input.txt", "r", stdin);
	int T;
	cin >> T;
	FOR(testcase, 1, T)
	{
		cin >> h >> w;
		FOR(row, 1, h)
		{
			FOR(col, 1, w)
			{
				cin >> stones[row][col];
				if(row > 1)
				{
					int left = 0, right = 0, above = 0;
					if(col > 1)
						left = stones[row-1][col-1];
					if(col < w)
						right = stones[row-1][col+1];
					above = stones[row-1][col];

					int max = above;
					max = max > left ? max : left;
					max = max > right ? max : right;

					stones[row][col] += max;
				}
			}
		}

		int maxStone = 0;
		FOR(col, 1, w)
			if(stones[h][col] > maxStone)
				maxStone = stones[h][col];

		cout << maxStone << endl;

	}
	getch();
	return 0;
}


Output:
1
2
3
4
Line 18: error: conio.h: No such file or directory
In function 'int main()':
Line 52: error: 'getch' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: