zoukankan      html  css  js  c++  java
  • HDU1087:Super Jumping! Jumping! Jumping!(DP水题)

    Super Jumping! Jumping! Jumping!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 63733    Accepted Submission(s): 29669


    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.



    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
     
     
    题意:
    一条直线上有N个点,每个点有对应值,从最左边的起点(视为0)开始,跳到右边值大于它的点上,然后将值更新为跳到的点的值,问跳到终点(视为无限大)所经过的值的和最大为多少。
    题解:
    由题目最多只有一千个点可以联想到直接DP即可,每个点枚举前面所有的点找出能跳到它的点的和最大的点(我在说什么……)。即用dp[N]记录每个点的最大的和。具体见下代码;
    #define _CRT_SECURE_NO_DepRECATE
    #define _CRT_SECURE_NO_WARNINGS
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <string>
    #include <algorithm>
    #include <bitset>
    #include <cstdlib>
    #include <cctype>
    #include <iterator>
    #include <vector>
    #include <cstring>
    #include <cassert>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #define ll long long
    #define INF 0x3f3f3f3f
    #define ld long double
    const ld pi = acos(-1.0L), eps = 1e-8;
    int qx[4] = { 0,0,1,-1 }, qy[4] = { 1,-1,0,0 }, qxx[2] = { 1,-1 }, qyy[2] = { 1,-1 };
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n, num[1001], dp[1001], maxx;
        while (cin >> n && n)
        {
            memset(dp, 0, sizeof(dp));
            for (int i = 0; i < n; i++)
            {
                cin >> num[i];
            }
            for (int i = 0; i < n; i++)
            {
                maxx = 0;
                for (int f = 0; f < i; f++)//遍历找出能跳到i的最大的值
                {
                    if (num[i] > num[f])
                    {
                        maxx = max(dp[f], maxx);
                    }
                }
                dp[i] = maxx + num[i];
            }
            for (int i = 0; i < n; i++)
            {
                maxx = max(maxx, dp[i]);
            }
            cout << maxx << endl;
        }
        return 0;
    }
  • 相关阅读:
    正则二三事
    docker elasticsearch 5.6.13 安装ik分词器
    centos docker 防火墙设置(多个ip之间互相访问)
    ElasticSearch结构化搜索和全文搜索
    Jest — ElasticSearch Java 客户端
    提高redis cluster集群的安全性,增加密码验证
    spring boot 设置 gzip 压缩
    centos 7磁盘空间满了导致redis cluster问题和kafka的问题
    SpringBoot之MySQL数据的丢失的元凶--事务(转)
    mysql mycat 1.6.6.1-release 批量 insert 数据丢失问题(续)
  • 原文地址:https://www.cnblogs.com/Load-Star/p/12662907.html
Copyright © 2011-2022 走看看