Created
September 15, 2018 09:43
-
-
Save completejavascript/3a415872555cd8b55ed61f88a1f41deb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int h, w; | |
int Matrix[101][101]; // Lưu giá trị lớn nhất tại mỗi ô | |
int main() | |
{ | |
int Testcase; | |
cin >> Testcase; | |
for(int tc = 0; tc < Testcase; tc++) | |
{ | |
// Nhập đầu vào | |
cin >> h >> w; | |
for(int row = 0; row < h; row++) | |
for(int col = 0; col < w; col++) | |
cin >> Matrix[row][col]; | |
// Bắt đầu xét từ dòng thứ 2 | |
for(int row = 1; row < h; row++) | |
{ | |
for(int col = 0; col < w; col++) | |
{ | |
int left = 0, above = 0, right = 0, temp = 0; | |
// Tại một ô, tôi sẽ kiểm tra giá trị của 3 ô phía trước nó | |
// là trên trái, trên phải và điểm ngay phía trên | |
if(col > 0) left = Matrix[row-1][col-1]; | |
if(col < w-1) right= Matrix[row-1][col+1]; | |
above = Matrix[row-1][col]; | |
// Tìm ra trường hợp lớn nhất | |
int max = left; | |
if(right > max) max = right; | |
if(above > max) max = above; | |
Matrix[row][col] += max; | |
} | |
} | |
// Tìm ra giá trị lớn nhất ở hàng cuối cùng | |
int max_stone = 0; | |
for(int col = 0; col < w; col++) | |
if(Matrix[h-1][col] > max_stone) max_stone = Matrix[h-1][col]; | |
cout << max_stone << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment