标签:style blog http color os io for art
没什么好说的,这是我学DP的第一道题目。
1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 using namespace std; 7 8 int a[103][103]; 9 10 int main(void) 11 { 12 #ifdef LOCAL 13 freopen("2084in.txt", "r", stdin); 14 #endif 15 16 int C; 17 scanf("%d", &C); 18 while(C--) 19 { 20 int n; 21 scanf("%d", &n); 22 int i, j; 23 for(i = 1; i <= n; ++i) 24 for(j = 1; j <= i; ++j) 25 scanf("%d", &a[i][j]); 26 27 for(i = n-1; i >= 1; --i) 28 for(j = 1; j <= i; ++j) 29 a[i][j] += max(a[i+1][j], a[i+1][j+1]); 30 31 printf("%d\n", a[1][1]); 32 } 33 return 0; 34 }
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/3877007.html