Love of the Philosopher's Stone

Source: Internet
Author: User

"Problem description"

In Harry Potter and the Sorcerer's Stone, to get the magic stone, you have to go through a lot of tests and games. Now Albus Dumbledore believes that these games are magical, wizards can easily pass, and we need to add some problems that can only be solved by the intellect, which requires the real smart people to pass. Now because our beloved Harry Potter classmate time is limited, need your help, ask you to help him to solve this problem. The Magic stone must be obtained before Voldemort in order to protect the magic world.

The rules of the game are as follows:

Existing game, play it will have a block in order to fall from the top of the screen to the bottom, when it hit an obstacle or the bottom will stop, and become an obstacle. Rules of the game, only from the square before the whereabouts of the decision to drop the horizontal position, so that the block into an obstacle after the height of the lowest, and if there are several lateral position so that the block becomes an obstacle after the height of the lowest, take the leftmost lateral position drop.

"Input File" (stone.in)

(1) The first line has 2 integers, the number of squares n and the screen width W.

(2) 2 rows to n+1 lines of 1 integers per line, the edge length of block I is a.

"Output File" (stone.out)

The output file Stone.out contains only one integer, which is the highest point height of the last obstacle.

"Input Sample"

3 5

2

1

3

"Output Example"

4

Comments

The green is the Block 1, the Blue is the Block 2, the purple is the square 3.

Each time you choose to guarantee the bottom point and the left

"Data Size"

For 100% of data

1<=w<=20

1<=a<=w

1<=n<=100

/*Simulation*/#include<cstdio>#include<iostream>#defineN 25#defineINF 1000000000using namespacestd;intHigh[n],w,n;intMain () {Freopen ("jh.in","R", stdin); scanf ("%d%d",&n,&W);  for(intI=1; i<=n;i++)    {        inta,pos,minn=INF; scanf ("%d",&a);  for(intj=1; j+a-1<=w;j++)        {            intmaxn=0;  for(intk=1; k<=a;k++) MAXN=max (maxn,high[k+j-1]); if(maxn<Minn) {POS=J; Minn=MAXN; }        }         for(intj=1; j<=a;j++) High[j+pos-1]=minn+A; }    intans=0;  for(intI=1; i<=n;i++) ans=Max (ans,high[i]); printf ("%d", ans); return 0;}
View Code

Love of the Philosopher's Stone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.