USACO 1.5 Number Triangles

经典的数字三角形

 1 /*

 2 ID: cuizhe

 3 LANG: C++

 4 TASK: numtri

 5 */

 6 #include <cstdio>

 7 #include <cstring>

 8 #include <cmath>

 9 #include <algorithm>

10 using namespace std;

11 #define LL long long

12 int dp[1001][1001];

13 int main()

14 {

15     int i,j,n;

16     freopen("numtri.in","r",stdin);

17     freopen("numtri.out","w",stdout);

18     scanf("%d",&n);

19     for(i = 1;i <= n;i ++)

20     {

21         for(j = 1;j <= i;j ++)

22         scanf("%d",&dp[i][j]);

23     }

24     for(i = n-1;i >= 1;i --)

25     {

26         for(j = 1;j <= i;j ++)

27         {

28             dp[i][j] += max(dp[i+1][j],dp[i+1][j+1]);

29         }

30     }

31     printf("%d\n",dp[1][1]);

32     return 0;

33 }

你可能感兴趣的:(number)