JOJ 2491 What is your level? 【动态规划解法】

动态规划:

 

[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]

你可能感兴趣的:(level)