zoukankan      html  css  js  c++  java
  • HDU

    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

    一道很典型的DP,题目的特点在所选择的序列中,后一个数要严格大于前一个数。

    对于这种DP,我的一种思路就是“多线程”的思想,因为如果只用一个序列的话,很有可能“一叶障目,不见泰山”。多线程可以避免掉这一不足,但是有可能会导致超时。

    回到题目本身,dp[i]代表的是前i项(包括第i项)最大的和,于是我就让con[i]和前面所有的(con[i]>con[j],j>=1&&j<i)dp[j]相加,取最大的那个和。

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string.h>
     4 #include<math.h>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<stack>
     8 #include<deque>
     9 #include<iostream>
    10 using namespace std;
    11 typedef long long  LL;
    12 int con[1009];
    13 int dp[1009];
    14 int main()
    15 {
    16     LL i,p,j,n,t;
    17     LL mid,head;
    18     while(scanf("%lld",&n)!=EOF)
    19     {
    20         if(n==0)
    21             break;
    22         for(i=1;i<=n;i++)
    23             scanf("%d",&con[i]);
    24         memset(dp,0,sizeof(dp));
    25         dp[1]=con[1];
    26         for(i=2;i<=n;i++)
    27         {
    28             head=-1;
    29             for(j=1;j<i;j++)
    30             {
    31                 if(con[i]>con[j])
    32                 {
    33                     mid=dp[j]+con[i];
    34                     if(mid>head)
    35                         head=mid;
    36                 }
    37             }
    38             if(head==-1)
    39                 dp[i]=con[i];
    40             else
    41                 dp[i]=head;
    42         }
    43         head=-1;
    44         for(i=1;i<=n;i++)
    45             if(dp[i]>head)
    46                 head=dp[i];
    47         printf("%lld
    ",head);
    48     }
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    批量更新sql |批量update sql
    智力测试题3
    【管理心得之二十一】管得少就是管得好
    查看sqlserver被锁的表以及如何解锁
    AD域相关的属性和C#操作AD域
    毕业5年小结一下
    WPF版公司的自动签到程序
    用友畅捷通高级前端笔试题(一)凭借回忆写出
    .NET中制做对象的副本(三)通过序列化和反序列化为复杂对象制作副本
    .NET中制做对象的副本(二)继承对象之间的数据拷贝
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9384592.html
Copyright © 2011-2022 走看看