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