HDU 4293 groups (linear DP)

Source: Internet
Author: User

OJ question: Click Here ~~

Question Analysis: N people are divided into several groups. Each person describes the number of people in front of the group and the number of people in the back. Find the maximum number of correct n descriptive descriptions.

If DP [I] is the maximum number of correct descriptions in the previous one, DP [N] is required. Num [I] [J] Save that there are I people before, and there are j people behind, obviously num [I] [J] cannot exceed n-I-j;

Transfer Equation DP [I] = max (DP [I], DP [J] + num [J] [n-I]). For details, see Code gaze.

Ac_code

Int num [502] [502]; int DP [502]; int main () {// freopen ("in.txt", "r", stdin); int N; while (CIN> N) {memset (Num, 0, sizeof (Num); memset (DP, 0, sizeof (DP); int I, j,, b; for (I = 1; I <= N; I ++) {scanf ("% d", & A, & B ); if (a + B <n & num [a] [B] <(n-a-B) num [a] [B] ++ ;} for (I = 1; I <= N; I ++) // for personal I for (j = 0; j <I; j ++) // he may be expressed as having J people before, J in [0 I-1], so it's DP [J] + num [J] [] DP [I] = max (DP [I], DP [J] + num [ J] [n-I]); // Why is the two-dimensional representation of num [n-I]? In this way, we can ensure that 2 for will traverse all the num [I] [J] for this traversal.! Cout <DP [N] <Endl;} 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.