zoukankan      html  css  js  c++  java
  • 2016huasacm暑假集训训练五 F

    题目链接:https://vjudge.net/contest/126708#problem/F

    题意:求至上而下一条路径的所经过的值得和最大值,这题比赛时就出了 但当时看不懂题目一直没写,这就和数字三角形差不多,只是加上了他的下部分,分上下两种情况就行。

    AC代码:

     1 #include<cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 using namespace std;
     5 int i,j,n;
     6 long long a[200][200],f[200][200],ans;
     7 int main()
     8 {
     9     int t2;
    10     scanf("%d",&t2);
    11     for(int t1 = 1; t1 <= t2; t1++)
    12     {
    13         scanf("%d",&n);
    14         for(i = 1; i <= 2*n-1; i++)
    15             for(j = 1; j <= min(i,2*n - i); j++)
    16             {
    17                 scanf("%lld",&a[i][j]);
    18             }
    19         memset(f,0,sizeof(f));
    20         for(i = 1; i <= 2*n-1; i++)
    21             for(j = 1; j <= min(i,2*n - i); j++)
    22             {
    23                 if(i == 1) f[i][j] = a[i][j];
    24                 if(i<=n)
    25                 {
    26                    f[i][j] = max(f[i-1][j], f[i - 1][j - 1]) + a[i][j];
    27                 }
    28                 else
    29                 {
    30                  f[i][j] =  max(f[i-1][j], f[i - 1][j + 1]) + a[i][j];
    31                 }
    32             }
    33         printf("Case %d: %lld",t1,f[2*n-1][1]);
    34        putchar('
    ');
    35 
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    Python-Matplotlib 12 多图figure
    Python-Matplotlib 11 子图-subplot
    Python Day16
    Python Day15
    Python Day13-14
    Python Day12
    Python Day11
    Python Day9-10
    Python Day8
    Python Day8
  • 原文地址:https://www.cnblogs.com/LIUWEI123/p/5757078.html
Copyright © 2011-2022 走看看