HDU 1176 free pie

Source: Internet
Author: User

The question is simple: How many pies can he receive?


If a two-dimensional time position table is displayed, it is easy to see that the table is the same as that of hangdian's 2084 data towers. You can start to push up from the bottom to see the maximum sum. He has three options except 0 and 10.
Such as the sum in the brackets. The row represents the time t, and the column represents the position.


Note: The starting point must start from 5 (green area), so the final result should be the maximum value here.

 


AC code:

# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> using namespace std; int dp [100010] [11]; int main () {int n, I, j, maxx, tim, x, t; while (scanf ("% d", & n) {tim = 0; memset (dp, 0, sizeof (dp); for (I = 0; I <n; I ++) {scanf ("% d", & x, & t); dp [t] [x] ++; if (t> tim) // record Max time {tim = t ;}} maxx = 0; for (I = tim-1; I> = 0; I --) // sum from the penultimate layer {for (j = 0; j <11; j ++) {if (j = 0) {dp [I] [j] = max (dp [I] [j] + dp [I + 1] [j], dp [I] [j] + dp [I + 1] [j + 1]);} else {if (j = 10) {dp [I] [j] = max (dp [I] [j] + dp [I + 1] [j], dp [I] [j] + dp [I + 1] [J-1]);} else {dp [I] [j] = max (dp [I] [j] + dp [I + 1] [j], dp [I] [j] + dp [I + 1] [J-1]), dp [I] [j] + dp [I + 1] [j + 1]) ;}} if (dp [I] [j]> maxx) {maxx = dp [I] [j] ;}} printf ("% d \ n", dp [0] [5]);} return 0 ;} # include <iostream> # include <cstdio> # include <algorithm> # include <cstring> using namespace std; int dp [100010] [11]; int main () {int n, I, j, maxx, tim, x, t; while (scanf ("% d", & n) {tim = 0; memset (dp, 0, sizeof (dp); for (I = 0; I <n; I ++) {scanf ("% d", & x, & t); dp [t] [x] ++; if (t> tim) // record Max time {tim = t ;}} maxx = 0; for (I = tim-1; I> = 0; I --) // sum from the penultimate layer {for (j = 0; j <11; j ++) {if (j = 0) {dp [I] [j] = max (dp [I] [j] + dp [I + 1] [j], dp [I] [j] + dp [I + 1] [j + 1]);} else {if (j = 10) {dp [I] [j] = max (dp [I] [j] + dp [I + 1] [j], dp [I] [j] + dp [I + 1] [J-1]);} else {dp [I] [j] = max (dp [I] [j] + dp [I + 1] [j], dp [I] [j] + dp [I + 1] [J-1]), dp [I] [j] + dp [I + 1] [j + 1]) ;}} if (dp [I] [j]> maxx) {maxx = dp [I] [j] ;}} printf ("% d \ n", dp [0] [5]);} 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.