码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • USACO Training 1.5 Number Triangles


    Consider the number triangle shown below. Write a program that calculates the highest sum of numbers that can be passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.

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

    In the sample above, the route from 7 to 3 to 8 to 7 to 5 produces the highest sum: 30.

    PROGRAM NAME: numtri

    INPUT FORMAT

    The first line contains R (1 <= R <= 1000), the number of rows. Each subsequent line contains the integers for that particular row of the triangle. All the supplied integers are non-negative and no larger than 100.

    SAMPLE INPUT (file numtri.in)

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

    OUTPUT FORMAT

    A single line containing the largest sum using the traversal specified.

    SAMPLE OUTPUT (file numtri.out)

    30

    题目的大致意思就是让你在这个number triangle往斜方,正下方,找最大的树,问最大的这些数的和是多少。

    usaco还有一个奇怪的规则,输出完必须加endl。。。要不然过不了!

    1. /*
    2. ID: choiyin1
    3. LANG: C++
    4. TASK: numtri
    5. */
    6. #include
    7. using namespace std;
    8. int n,ans;
    9. int main() {
    10. freopen("numtri.in", "r", stdin);
    11. freopen("numtri.out", "w", stdout);
    12. cin >> n;
    13. int numMax[1050];
    14. int num[1050];
    15. for (int i = 1; i <= n; i ++){
    16. for (int j = 1; j < i + 1; j ++)
    17. cin>>num[j];
    18. for (int j = i; j > 0; j --)
    19. numMax[j] = max(numMax[j - 1], numMax[j]) + num[j];
    20. }
    21. for (int i = 1; i<= n; i ++){
    22. ans = max(ans, numMax[i]);
    23. }
    24. cout << ans<
    25. }

  • 相关阅读:
    重启服务器后,由于内核自动升级,显卡无法使用,卸载不彻底,重装失败,安装日志报如下问题
    13.TCP-bite
    数据集积累学习---CoCo数据集(and others)
    PythonQt打包发布exe应用注意事项,解决错误no Qt platform plugin found
    STM32 J-LINK
    Linux关于gittee的远端仓库的连接和git三板斧
    持续部署:提高敏捷加速软件交付(内含教程)
    vue 项目搭建的几种方式
    客户端发现pod并与之通信
    基于决策树的智能网络安全入侵检测模型
  • 原文地址:https://blog.csdn.net/GeekAlice/article/details/127129231
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号