1644 free pie question (c ++) (S. B. S.), 1644s. B .s.

Source: Internet
Author: User

1644 free pie question (c ++) (S. B. S.), 1644s. B .s.

1644 free pie (number on Bashu oj)

Question:

SERKOI recently launched a game called "free pie. The game is played on a stage. The width of the stage is W, the height of the skyscreen is H, and players share one grid. At the beginning, the gamer stood in the center of the stage and held a tray in his hand. After the game started, the pie continued to appear and fall vertically from the lattice at the top of the scenes on the stage. Players move around to pick up pies. Players can move one or two cells to the left or right of each second, or they can stand on the ground as expected. There are many types of pies. The gamer scores all the pies in sequence based on his own taste. At the same time, under the remote control of 8-computers, the falling speed of various pies is also different. The falling speed is measured in cells/s. When the pie arrives at the end of a second in the grid where the gamer is located, the gamer collects the pie. Write a program to help our players collect pies and maximize the sum of collected pies. Input data: the first line: W (1 ~ 99 ODD) and H (1 ~ An integer of 100. It consists of four positive integers, indicating the initial fall time, horizontal position, fall speed, and score of the pie. The start time of the game is 0. Numbers of each cell in the horizontal direction from 1 to left and right. Output Data: The sum of the largest scores of collected pies. -------------- Split line ---------------------------------------------------- Question: Because the time and speed of the pie fall are different, people can only move to the left and right, and the pie can only move down. As people and pies move at the same time, it is complicated to think about, so we need to change our thinking: Calculates the number of pie points that fall to the bottom of each grid at each time point. If the pie is used as a reference object, the pie may fall as if the pie is not moving, and people go up to pick up the pie, so that each person can go to the five grids in the previous line at every 1 moment,This question is: The deformation of the classic Dynamic Scaling Model of the number Tower, the position where the pie Falls is regarded as the number of columns in the number column, and the falling time as the number of rows in the number column, the problem is transformed into the longest path from the bottom of the tower to the top of the tower. Calculate the possible pie points of each grid at each time point, and fill in the canopy table of w * H. Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace std; int w, h; struct pie {int time, pos, speed, value, t;} s [10001]; // use struct to record data int f [1001] [1001]; // record decision int main () {cin> w> h; int n = 1, ss, maxn =-999, ans = 0; // while (scanf ("% d", s [n]. time, s [n]. pos, s [n]. speed, s [n]. value) = 4) while (cin> s [n]. time> s [n]. pos> s [n]. speed> s [n]. value) // because you do not know the number of data, use while to read {s [n]. t = ceil (h/s [n]. speed) + s [n]. time; // t indicates the time when the pie falls down (to the last grid) n ++; // the core of this step is to round the time, but it is a plus one (2 ..... = 3)} n-= 1; // n is the number of pies for (int I = 1; I <= n; I ++) {f [s [I]. pos] [s [I]. t] + = s [I]. value; maxn = max (s [I]. t, maxn); // find the last pie time} for (int j = maxn-1; j> = 0; j --) for (int I = 1; I <= w; I ++) {if (f [I-2] [j + 1] & I-2> 0) ans = max (ans, f [I-2] [j + 1]); if (f [I-1] [j + 1] & I> 1) ans = max (ans, f [I-1] [j + 1]); if (f [I] [j + 1]) ans = max (ans, f [I] [j + 1]); if (f [I + 2] [j + 1] & I + 2 <= w) ans = max (ans, f [I + 2] [j + 1]); if (f [I + 1] [j + 1] & I + 1 <= w) ans = max (ans, f [I + 1] [j + 1]); f [I] [j] + = ans; // state transfer equation application} cout <f [w/2 + 1] [0]; // output (w/2 +) because the person starts from the center) return 0 ;}

 

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.