Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
简单的dp,发代码纪念一下/*我把三角形绕中轴旋转了处理的*/ #include <stdio.h> #include <limits.h> int dp_table[102]; int max_sum( int row ) { int i , j; int max_value ; for ( i = 0 ; i<= row+1 ; i++) { dp_table[i] = INT_MIN; } scanf("%d" , & dp_table[1]); for ( i = 2 ; i <= row ; i++) { for ( j = i ; j > 0 ; j--) { int new_value; scanf("%d" , &new_value); max_value = dp_table[j] + new_value; if ( dp_table[j] < dp_table[j-1]) { max_value = dp_table[j-1] + new_value; } dp_table[j] = max_value; } } max_value = 0; for ( i = 1 ; i <= row ; i++) { if ( dp_table[i]>max_value) { max_value = dp_table[i]; } } return max_value; } int main(void) { int row; scanf("%d" , &row); printf("%d" ,max_sum(row) ); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator