261. [NOI1997] Bricks Game
★ Import File: buildinggame.in output file: buildinggame.out Simple comparison
Time limit: 1 s memory limit: MB
Sercoi recently designed a game of bricks. Each player has n blocks numbered 1, followed by a 2,...,n box block. For each block, its three different sides are called "a-side", "B-side", and "C-side", as shown:
The rules of the game are as follows:
- Select several blocks from the N block and divide them into m (l<=m<=n) heaps, called the 1th heap, the 2nd heap ..., and the first heap. There are at least 1 blocks per heap, and the number of any block in the K heap is greater than the number of any block in the K+1 heap (2<=k<=m).
- For each pile of bricks, the player will stack them vertically into a pillar and require the following two conditions to be fulfilled:
- In addition to the topmost block, the upper surface of any block is in contact with the lower surface of the other block, and requires that the upper surface of the building block below contain the lower surface of the building blocks above, that is to say, the length of the two pairs of sides of the upper surface of the building block above is equal to the length of the two opposite sides of the
- For any two blocks touching the upper and lower surfaces, the building blocks below are numbered less than the building blocks above.
Finally, the sum of the height of the M-pillars piled up by each person is determined.
Please make up a program to find a stack of bricks, so that you stack the height of the M-pillars of the largest.
Input/Output
The first line of the input file has two positive integers N and M (1<=m<=n<=100), each representing the total number of bricks and the number of columns required to stack. The two numbers are separated by a space character. The next n rows are the dimensions of n bricks numbered from 1 to N, each line having three integers between 1 and 1000, representing the length of the Block A, B and C sides, respectively. The same line is separated by a space character between the two adjacent numbers.
The output file has only one row and is an integer representing the sum of the height of the M-pillar.
Sample Example
Input file
425587722 2 66 6
Output file
24
Water DP.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn= the;6 inta[maxn][3];7 intdp[maxn][maxn][3],n,m;8 intMain () {9Freopen ("buildinggame.in","R", stdin);TenFreopen ("Buildinggame.out","W", stdout); Onescanf"%d%d",&n,&m); A for(intI=1; i<=n;i++) -scanf"%d%d%d", &a[i][0],&a[i][1],&a[i][2]); -Memset (DP,0x80,sizeof(DP)); dp[0][0][0]=dp[0][0][1]=dp[0][0][2]=0; the for(intI=1; i<=m;i++) - for(intj=1; j<=n;j++) - for(intH=0; h<j;h++) - for(intk=0; k<=2; k++) + for(intL=0; l<=2; l++){ - intX1,y1,x2,y2; +x1=A[h][k]; Ay1=a[h][(k +1)%3]; atX2=A[j][l]; -y2=a[j][(L +1)%3]; - if(x1>y1) swap (x1,y1); - if(x2>y2) swap (x2,y2); - if(x1>=x2&&y1>=y2) -Dp[i][j][l]=max (dp[i][j][l],dp[i][h][k]+a[j][(l +2)%3]); inDp[i][j][l]=max (dp[i][j][l],dp[i-1][h][k]+a[j][(L +2)%3]); - } to intans=0; + for(intI=1; i<=n;i++) -Ans=max (Ans,max (Max (dp[m][i][0],dp[m][i][1]), dp[m][i][2])); theprintf"%d\n", ans); * return 0; $}
Dynamic planning (water problem): COGS 261. [NOI1997] Bricks Game