Created
August 23, 2015 20:12
-
-
Save schweigert/e38fccd89eaa4429e3f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <stdio.h> | |
| int Mat[100][100] = {0}; | |
| int Sun[100][100] = {0}; | |
| int Tam = 0; | |
| void ResetSun (){ | |
| int i, j; | |
| for (i = 0; i < 100; i++){ | |
| for (j = 0; j < 100; j++){ | |
| Sun [i][j] = -1; | |
| } | |
| } | |
| } | |
| int MaiorSoma (int i, int j){ | |
| if (i != 0 && Sun[i][j] != -1){ | |
| return Sun[i][j]; | |
| } | |
| if (i < Tam){ | |
| int esq = Mat[i][j] + MaiorSoma(i+1,j); | |
| int dir = Mat[i][j] + MaiorSoma(i+1,j+1); | |
| if (esq > dir){ | |
| Sun [i][j] = esq; | |
| return esq; | |
| } else { | |
| Sun [i][j] = dir; | |
| return dir; | |
| } | |
| }else { | |
| return 0; | |
| } | |
| } | |
| int main (void) { | |
| int i, j, k, s; | |
| scanf ("%d", &s); | |
| while (s--){ | |
| scanf ("%d", &k); | |
| for (i = 0; i < k; i++){ | |
| for (j = 0; j <= i; j++){ | |
| scanf ("%d", &Mat[i][j]); | |
| } | |
| } | |
| ResetSun (); | |
| Tam = k; | |
| printf ("%d\n", MaiorSoma(0,0)); | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment