POJ 3176 (DP)
题目:http://poj.org/problem?id=3176
bowl[i][j] += max( bowl[i-1][j-1], bowl[i-1][j]);
代码:
#include <stdio.h> #include <string.h> int bowl[355][355]; int main() { int row,i,j,tmp; while(~scanf("%d",&row)) { for(i = 0 ; i < row ; ++i) for(j = 0 ; j <= i ; ++j) scanf("%d",&bowl[i][j]); for(i = 1 ; i < row ; ++i) { bowl[i][0] += bowl[i-1][0]; bowl[i][i] += bowl[i-1][i-1]; } for(i = 2 ; i < row ; ++i) for(j = 1 ; j < i ; ++j) { tmp = bowl[i-1][j-1] > bowl[i-1][j] ? bowl[i-1][j-1]: bowl[i-1][j]; bowl[i][j] += tmp; } tmp = -1; for(i = 0 ; i < row ; ++i) if(bowl[row-1][i] > tmp) tmp = bowl[row-1][i]; printf("%d\n",tmp); } //system("pause"); return 0; }