zoukankan      html  css  js  c++  java
  • E

    /*

    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. 


    状态分析 node(pos,num,sum) (k+1).sum = max((i--k).sum) +(k+1).num */ #include<iostream> #include<vector> #include<cstdlib> #include<cstdio> using namespace std; int N; int main() { int i,j; int a[1000]; int sum[1000]; cin>>N; while(N!=0) { int all_max = -1; memset(a,-1,sizeof(a)); memset(sum,0,sizeof(sum)); for(i=0;i<N;i++) { cin>>a[i]; if(i==0) { sum[0] = a[i]; continue; } int max = -1; bool sign = true; for(j=0;j<i;j++)//找出i之前位置中小于a[i]的位置中最大的sum,如果没有就sign = true { if(a[j]<a[i]) { sign = false; if(sum[j]>max) max = sum[j]; } } if(sign)//此时sum值为a[i] sum[i] = a[i]; else //否则状态转移方程可知 sum[i] = a[i] + max; if(sum[i]>all_max) all_max = sum[i]; } cout<<all_max<<endl; cin>>N; } }
  • 相关阅读:
    js去掉字符串前后空格三种方法及最佳方案
    javascript笔记:Date对象及操作方法
    高性能网站建设指南总结
    javascript之词法作用域及函数的运行过程
    LETTers比赛第四场N!
    LETTers比赛第三场 1003 大明A+B解题报告
    LETTers比赛第三场 1004 Max Sum Plus Plus 解题报告
    LETTers比赛第三场 1002 Ignatius and the Princess III解题报告
    LETTers第五场Sleeping 解题报告
    LETTers比赛第四场N!的最高位
  • 原文地址:https://www.cnblogs.com/joeylee97/p/6128762.html
Copyright © 2011-2022 走看看