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 ;}