H-super jumping! jumping! jumping!Time

**limit:**1000MS

**Memory Limit:**32768KB

**64bit IO Format:**%i64d &%i64 U SubmitStatusPracticeHDU 1087Appoint Description:System Crawler (2015-11-18)

Description

Nowadays, a kind of chess game called "Super jumping! jumping! Jumping! "is very popular in HDU. Maybe you is a good boy, and know little about the this game, so I introduce it to you now.

The game can be played by and more than the players. It consists of a chessboard (chessboard) and some chessmen (chess pieces), and all chessmen is marked by a positive integer or "start" or "End ”. The player starts from start-point and must jumps to end-point finally. In the course of jumping, the player would visit the chessmen in the path, but everyone must jumps from one Chessman to Ano Ther absolutely bigger (you can assume start-point are 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 can straightly get to end-point From Start-point. Of course you get the 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 was described in a line as follow:

N value_1 value_2 ... value_n

It is guarantied, that N was not more than, and all value_i be in the range of 32-int.

A test case, starting with 0 terminates, the input and this test are not 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

4103

#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;Const intmaxn=1005;intVALUE[MAXN];intDP[MAXN];intMain () {intN; //scanf ("%d", &n); while(SCANF ("%d", &n)! =EOF) { if(n==0) Break; for(intI=1; i<=n;i++) {scanf ("%d",&Value[i]); Dp[i]=Value[i]; } intans=-1; for(intI=1; i<=n;i++){ for(intj=1; j<i;j++){ if(value[i]>value[j]&&dp[i]<dp[j]+Value[i]) dp[i]=dp[j]+Value[i]; } ans=Max (ans,dp[i]); } printf ("%d\n", ans); } return 0;}

I-monkey and BananaTime

**limit:**1000MS

**Memory Limit:**32768KB

**64bit IO Format:**%i64d &%i6 4u SubmitStatusPracticeHDU 1069Appoint Description:Prayerhgq (2015-08-04)System Crawler (2015-11-23)

Description

A group of researchers is designing an experiment to test the IQ of a monkey. They a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall being able to reach the banana by placing one block on the top another to build a to Wer and climb up to get their favorite food.

The researchers has n types of blocks, and an unlimited supply of blocks of each type. Each type-i block is a rectangular solid with linear dimensions (xi, Yi, zi). A Block could is reoriented so it three dimensions determined the dimensions of the base and the other Di Mension was the height.

They want to make sure, the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only being placed on top of the another block as long as the the and the both base D Imensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because There have to is some space for the monkey to step on. This is meant, for example, which blocks oriented to has equal-sized bases couldn ' t be stacked.

Your job is to write a program this determines the height of the tallest tower the monkey can build with a given set of BL Ocks.

Input

The input file is contain one or more test cases. The first line of all test case contains an integer n,

Representing the number of different blocks in the following data set. The maximum value for n is 30.

Each of the next n lines contains three integers representing the values XI, Yi and Zi.

Input is terminated by a value of zero (0) for N.

Output

For each test case, print one line containing the case number (they is numbered sequentially starting from 1) and the HEI Ght of the tallest possible tower in the format "case case:maximum height = height".

Sample Input

1 10 20 30 2 6 8 10 5 5 5 7 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 5 31 41 59 26 53 58 97 93 23 84 62 64 33 83 27 0

Sample outputcase 1:maximum height = 40Case 2:maximum height = 21Case 3:maximum height = 28Case 4:maximum height = 342 Each lattice up to 3 states, that is, up to 3 kinds of high, that is, a total of n*3 up to 90 lattice, but X and y can be swapped, then up to 180, I to 180 lattice pairs x from small to large sort, x equal, Y is small to large order, Then this problem can be converted into the same way as the maximum increment sub-sequence problem dp,dp[i] to indicate the maximum value of the first lattice, Dp[i+1] is the former I find the largest one to meet the conditions of a plus to go, because, the heavy floor must x smaller and larger, in turn, X is getting bigger, I've guaranteed that x is incremented, so DP is right! The C + + code is as follows:

#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;Const intmaxn= $;structnode{intx, Y, Z;} DP[MAXN];BOOLcmpConst structNode T1,Const structnode T2) { if(t1.x!=t2.x)returnt1.x<t2.x; returnt1.y<t2.y;}intMain () {intcas=1; intN; while(SCANF ("%d", &n)! =EOF) { intCnt=0; if(n==0) Break; intTx,ty,tz; for(intI=1; i<=n;i++) {scanf ("%d%d%d",&tx,&ty,&TZ); dp[cnt].x=tx,dp[cnt].y=ty,dp[cnt].z=tz,cnt++; dp[cnt].x=tx,dp[cnt].y=tz,dp[cnt].z=ty,cnt++; dp[cnt].x=ty,dp[cnt].y=tx,dp[cnt].z=tz,cnt++; dp[cnt].x=ty,dp[cnt].y=tz,dp[cnt].z=tx,cnt++; dp[cnt].x=tz,dp[cnt].y=tx,dp[cnt].z=ty,cnt++; dp[cnt].x=tz,dp[cnt].y=ty,dp[cnt].z=tx,cnt++; } sort (DP,DP+cnt,cmp); for(intI=0; i<cnt;i++){ inttmp=-1; for(intj=0; j<i;j++){ if(((dp[i].x>dp[j].x) && (dp[i].y>dp[j].y) | | ((DP[I].X>DP[J].Y) && (dp[i].y>dp[j].x))) && (dp[j].z>tmp)) {tmp=dp[j].z; } } if(tmp!=-1) Dp[i].z+=tmp; } intans=-1; for(intI=0; i<cnt;i++) {ans=Max (ANS,DP[I].Z); } printf ("Case %d:maximum height =%d\n", cas++, ans); } return 0;}

HDU 1069&&hdu 1087 (sum of DP longest sequences)