PAT 1045

题目 : Favorite Color Stripe

分值 : 30
难度 : 中等题
思路 : 计数思维,按照他给的顺序每次进来一个,最大的值就是该颜色之前所有的子颜色最大值+1
       这个和 Count PAT 有点类似,就是你记录下P的值,每次进来一个T那么PT就是 之前的P
       个数,
坑点 : 没遇见坑点
评语 : 一次AC还OK

具体代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std ;
int color[201] ;
int order[201] ;
int order2[201] ;
int main() {
int N , M;
cin >> N >>M ;
for(int i = 0 ; i< M ; i++)
{
cin >> order[i] ;
order2[ order[i] ] = i ;
}
int L ,temp;
cin >> L ;
for(int i = 0 ; i< L ;i++)
{
cin>> temp ;
int max= 0 ;
for(int j = 0 ; j<=order2[temp] ;j++)
{
if(color[ order[j] ] > max)
max = color[order[j]] ;
}
color[ temp ] = max +1 ;
}
int ma = 0 ;
for(int i = 1; i<= N ; i++)
{
if(color[i] >ma)
ma=color[i] ;
}
cout<<ma <<endl ;
}