Cow Bowling

迈不过友情╰ 2022-07-16 02:18 251阅读 0赞

Cow Bowling














Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17749   Accepted: 11829

Description

The cows don’t use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this:

  1. 7
  2. 3 8
  3. 8 1 0
  4. 2 7 4 4
  5. 4 5 2 6 5

Then the other cows traverse the triangle starting from its tip and moving “down” to one of the two diagonally adjacent cows until the “bottom” row is reached. The cow’s score is the sum of the numbers of the cows visited along the way. The cow with the highest score wins that frame.

Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.

Input

Line 1: A single integer, N

Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.

Output

Line 1: The largest sum achievable using the traversal rules

Sample Input

  1. 5
  2. 7
  3. 3 8
  4. 8 1 0
  5. 2 7 4 4
  6. 4 5 2 6 5

Sample Output

  1. 30

Hint

Explanation of the sample:

  1. 7
  2. *
  3. 3 8
  4. *
  5. 8 1 0
  6. *
  7. 2 7 4 4
  8. *
  9. 4 5 2 6 5

The highest score is achievable by traversing the cows as shown above.

Source

USACO 2005 December Bronze

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int main()
  5. {
  6. int n,i,j;
  7. int a[400][400];
  8. scanf("%d",&n);
  9. for(i=1;i<=n;i++)
  10. {
  11. for(j=1;j<=i;j++)
  12. {
  13. scanf("%d",&a[i][j]);
  14. }
  15. }
  16. for(i=n;i>=1;i--)
  17. {
  18. for(j=1;j<=i;j++)
  19. {
  20. if(a[i][j]>a[i][j+1])
  21. {
  22. a[i-1][j]+=a[i][j];
  23. }
  24. else
  25. {
  26. a[i-1][j]+=a[i][j+1];
  27. }
  28. }
  29. }
  30. printf("%d\n",a[1][1]);
  31. return 0;
  32. }

发表评论

表情:
评论列表 (有 0 条评论,251人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Cow Gymnastics

    题目描述 为了提高健康水平,奶牛们开始进行体操训练了!Farmer John 选定了他最喜爱的奶牛 Bessie 来执教其他 N 头奶牛,同时评估她们学习不同的体操技术的

    相关 Catch That Cow

    think: 1广度优先搜索(队列思想) 2以结构数组为基础的队列思想 3反思:自己因为vis数组有的初始化位置不对,导致runtime error.??? hi