当前位置: 首页 > news >正文

Hdoj 1087.Super Jumping! Jumping! Jumping!

Problem Description

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
img
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.

Input

Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.

Output

For each case, print the maximum according to rules, and one line one case.

Sample Input

3 1 3 2
4 1 2 3 4
4 3 3 2 1
0

Sample Output

4
10
3

Author

lcy


思路

\(f[i]\)表示到位置\(i\)的最大和,显然状态转移方程为:

\(f[i] = max(f[j])+a[i](i:1→n;j:1→i-1)\)

代码

#include<bits/stdc++.h>
using namespace std;
int a[1001];
int f[1001];
int main()
{
    int n;
    while(cin>>n&&n!=0)
    {
        for(int i=1;i<=n;i++)
            cin >> a[i];
        int maxvalue = -1;
        memset(f,0,sizeof(f));
        
        for(int i=1;i<=n;i++)
        {
            int tmp = 0;
            for(int j=1;j<i;j++)
            {
                if(a[i] > a[j])
                    tmp = max(tmp,f[i]);
            }
            f[i] += a[i] + tmp;     //因为前面已经有a[i]>a[j]都逐个检验,所以这个a[i]一定是前面某个序列的最后一项
            maxvalue = max(maxvalue, f[i]);
        }
        cout << maxvalue << endl;
    }
            
    return 0;
}

转载于:https://www.cnblogs.com/MartinLwx/p/9829741.html

相关文章:

  • docker集群演练
  • UVA11090 Going in Cycle!!
  • 继承派生 属性查找
  • 针对shiro框架authc拦截器认证成功后跳转到根目录,而非指定路径问题
  • day06 再谈编码
  • React Native搭建开发环境 之 --走过的坑
  • noip2018复习计划啊
  • Linux之iptables(一、防火墙的概念)
  • 基于版本一致性算法
  • golang中的mutex锁
  • python中的__str__ __name__ 和__call__方法
  • JAVA程序打包方法-挺好
  • 【模拟题】异或 (二进制)
  • Xposed Hook Anti-hook
  • Failed to load property source from location 'classpath:/application.properties'
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • Android单元测试 - 几个重要问题
  • Android交互
  • JAVA多线程机制解析-volatilesynchronized
  • JS数组方法汇总
  • JS专题之继承
  • Nacos系列:Nacos的Java SDK使用
  • Shadow DOM 内部构造及如何构建独立组件
  • storm drpc实例
  • Vim Clutch | 面向脚踏板编程……
  • 关于extract.autodesk.io的一些说明
  • 基于遗传算法的优化问题求解
  • 入门到放弃node系列之Hello Word篇
  • 少走弯路,给Java 1~5 年程序员的建议
  • 深度解析利用ES6进行Promise封装总结
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 小程序滚动组件,左边导航栏与右边内容联动效果实现
  • 曾刷新两项世界纪录,腾讯优图人脸检测算法 DSFD 正式开源 ...
  • ​RecSys 2022 | 面向人岗匹配的双向选择偏好建模
  • # 达梦数据库知识点
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • (02)Hive SQL编译成MapReduce任务的过程
  • (2)STM32单片机上位机
  • (3)llvm ir转换过程
  • (C语言)strcpy与strcpy详解,与模拟实现
  • (libusb) usb口自动刷新
  • (WSI分类)WSI分类文献小综述 2024
  • (附源码)ssm本科教学合格评估管理系统 毕业设计 180916
  • (经验分享)作为一名普通本科计算机专业学生,我大学四年到底走了多少弯路
  • (十六)一篇文章学会Java的常用API
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (转)Scala的“=”符号简介
  • (转)shell中括号的特殊用法 linux if多条件判断
  • (转)拼包函数及网络封包的异常处理(含代码)
  • (转)为C# Windows服务添加安装程序
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • .NET Compact Framework 3.5 支持 WCF 的子集
  • .net core 实现redis分片_基于 Redis 的分布式任务调度框架 earth-frost
  • .NET LINQ 通常分 Syntax Query 和Syntax Method
  • .NET4.0并行计算技术基础(1)