Joj 2491 what is your level? [Dynamic Planning (barely classified )]

Source: Internet
Author: User

[Joj 2491]

 

[Original question link]

Http://acm.jlu.edu.cn/joj/showproblem.php? PID = 1, 2491

[Topic]

Enter the scores (Chinese and mathematics) of a group of students and classify the students. The grading method is to define the scores of one subject and one subject is higher than or equal to B, in this case, the level of A should be better than that of B. Each time, the level of A should be removed as the level, and the level of A should be downgraded, and so on. Enter the student ID and the output level.

You can also use DP, that is, based on the score DP:

If (score [I] [J]) level [I] [J] = (level [I + 1] [J]> level [I] [J + 1]? Level [I + 1] [J]: level [I] [J + 1]) + 1;

Else level [I] [J] = level [I + 1] [J]> level [I] [J + 1]? Level [I + 1] [J]: level [I] [J + 1];

This is the state transition equation. Other ideas are similar to the first method.

[Solution Thinking]

Use the score DP to classify students. It can also be classified from bottom to top.

 

[Code]

# Include <iostream>

# Include <cstdio>

# Include <cstring>

Using namespace STD;

 

Long student [200005] [2], score [410] [410], level [410] [410];

 

Int main ()

{

Long casenum, stunum, I, j, L, M, testnum, stuid;

Scanf ("% lD", & casenum );

While (casenum --)

{

Scanf ("% lD", & stunum );

Memset (score, 0, sizeof (score ));

For (I = 0; I <stunum; I ++)

{

Scanf ("% LD % lD", & Student [I] [0], & Student [I] [1]);

Score [student [I] [0] [student [I] [1] ++;

}

L = 0;

While (stunum)

{

M =-1;

L ++;

For (I = 400; I> = 0; I --)

{

For (j = 400; j> m; j --)

{// Actually, use the score traversal function to find students with the same score.

If (score [I] [J])

{

M = J;

Stunum-= score [I] [J];

Level [I] [J] = L;

Score [I] [J] = 0;

Break;

}

}

}

}

Scanf ("% lD", & testnum );

While (testnum --)

{

Scanf ("% lD", & stuid );

Printf ("% LD \ n", level [student [stuid] [0] [student [stuid] [1]);

}

}

Return 0;

}

[\ Code]

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.