Dynamic Planning:
 
 
 
 
 
 
 
[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] ++;
 
 
}
 
 
 
Level [401] [400] = 0; level [400] [401] = 0;
 
 
 
For (I = 400; I> = 0; I --)
 
 
 
{
 
 
 
For (j = 400; j> = 0; j --)
 
 
 
{
 
 
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];
 
 
 
}
 
 
 
}
 
 
Scanf ("% lD", & testnum );
 
 
 
While (testnum --)
 
 
 
{
 
 
 
Scanf ("% lD", & stuid );
 
 
 
Printf ("% LD \ n", level [student [stuid] [0] [student [stuid] [1]);
 
 
}
 
 
 
}
 
 
 
Return 0;
 
 
 
}
 
 
 
[\ Code]