[HDU 1176] free pie (DP)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1176

Train of thought; pre-process the number of biscuits at each position at each time point, and then perform DP by time. For details, refer to the code, and the implementation is very simple.

# Include <iostream> # include <stdio. h> # include <stdlib. h> # include <string. h >#include <algorithm> # define MAXN 100010 # define MAXM 15 using namespace std; int f [MAXN] [MAXM]; // f [I] [j] = time I stands in the position of the int num [MAXN] [MAXM] in the j bag; // num [I] [j] = the number of biscuits in position j when time I is used int max (int a, int B) {if (a> B) return; return B;} int main () {int n; while (scanf ("% d", & n )! = EOF & n) {memset (f, 0, sizeof (f); memset (num, 0, sizeof (num); int lastTime = 0; // lastTime = the time when the last biscuit falls for (int I = 1; I <= n; I ++) {int x, T; scanf ("% d", & x, & T); num [T] [x] ++; lastTime = max (lastTime, T );} for (int I = lastTime; I> = 0; I --) for (int j = 0; j <= 10; j ++) {f [I] [j] = f [I + 1] [j] + num [I] [j]; if (J-1> = 0) f [I] [j] = max (f [I] [j], f [I + 1] [j-1] + num [I] [j]); if (j + 1 <= 10) f [I] [j] = max (f [I] [j], f [I + 1] [j + 1] + num [I] [j]);} int ans = 0; for (int I = 0; I <= 10; I ++) ans = max (ans, f [0] [5]); printf ("% d \ n", ans);} return 0 ;}



[HDU 1176] free pie (DP)

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.