糟糕的打谱员
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
众所周知,围棋是一项黑白双方轮流行动的棋类游戏。在围棋中,还有打劫的概念,若一方落子在某一个劫争处,则另一方不能立刻也下在这个劫争处,而之后还是可以下的。现在,你是一场史诗级围棋对弈(史诗级体现在这场棋每一步都下在了劫争上)的记谱员,但熬夜到早上七点才睡的你状态不佳,胡乱记了许多东西。
为了假装你有出色的完成记谱工作,请从你记录的谱子中找到一个最长的合法行棋子序列。
一个合法行棋子序列需要满足:
1. 任意相邻的两步,玩家不同(一黑一白);
2. 任意相邻的两步,不能下在同一个劫争处。
子序列是指原序列中删除若干(可以不删)元素得到的新序列。
输入描述:
第一行是整数T(1≤T≤10)T(1≤T≤10),测试组数。 每组测试用例,第一行是整数n(3≤n≤105)n(3≤n≤105),你记录的谱子长度。 接下来nn行,每行两个数ci(0≤ci≤1)ci(0≤ci≤1)和ai(1≤ai≤10)ai(1≤ai≤10),表示一步棋,下这步棋的人是cici且下在了编号为aiai的劫争处。
输出描述:
每个测试用例输出一个整数,表示最长的合法行棋子序列长度。
示例1
输入
1 20 1 10 0 6 0 9 1 3 0 3 0 5 0 3 1 1 0 2 0 2 0 2 1 9 1 10 1 1 1 10 0 6 0 8 1 1 1 9 0 1
输出
10
/*
*@Author: GuoJinlong
*@Language: C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<list>
#include<set>
#include<iomanip>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<sstream>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
#define ls (p<<1)
#define rs (p<<1|1)
#define mid (l+r)/2
#define over(i,s,t) for(register long long i=s;i<=t;++i)
#define lver(i,t,s) for(register long long i=t;i>=s;--i)
const int MAXN = 305;
const int INF = 0x3f3f3f3f;
const int N=5e4+7;
const int maxn=1e5+5;
const double EPS=1e-10;
const double Pi=3.1415926535897;
//inline double max(double a,double b){
// return a>b?a:b;
//}
//inline double min(double a,double b){
// return a<b?a:b;
//}
int xd[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int yd[8] = {1, 0, -1, 0, -1, 1, -1, 1};
//void Fire(){
// queue<node> p;
// p.push({fx,fy,0});
// memset(fire, -1, sizeof(fire));
// fire[fx][fy]=0;
// while(!p.empty()){
// node temp=p.front();
// p.pop();
// for(int i=0;i<8;i++){
// int x=temp.x+xd[i];
// int y=temp.y+yd[i];
// if(x<0||x>=n||y<0||y>=m||fire[x][y]!=-1){
// continue;
// }
// fire[x][y]=temp.val+1;
// p.push({x,y,temp.val+1});
// }
// }
//}
//int bfs(){
// queue<node> p;
// memset(vis, 0, sizeof(vis));
// p.push({sx,sy,0});
// while (!p.empty()) {
// node temp=p.front();
// vis[temp.x][temp.y]=1;
// p.pop();
// for(int i=0;i<4;i++){
// int x=temp.x+xd[i];
// int y=temp.y+yd[i];
// if(x<0||x>=n||y<0||y>=m) continue;
// if(x==ex&&y==ey&&temp.val+1<=fire[x][y]) return temp.val+1;
// if(vis[x][y]||temp.val+1>=fire[x][y]||a[x][y]=='#') continue;
// p.push({x,y,temp.val+1});
// }
// }
// return -1;
//}
//一维哈希
//int n;
//string s;
//int bas=131;
//typedef unsigned long long ull;
//const ull mod1=100001651;
//ull a[100010];
//ull Hash(string s){
// ll ans=0;
// for(int i=0;i<s.size();i++){
// ans*=bas;
// ans+=int(s[i]);
// ans%=mod1;
// }
// return ans;
//}
//二维哈希
//using lom=unsigned long long ;
//const lom bas1=131,bas2=233;
//const int M=505;
//int n,m;
//char a[M][M];
//lom _hash[M][M];
//lom p1[M],p2[M];
//
//
//void init(){
// p1[0]=1;
// p2[0]=1;
// for(int i=1;i<=505;i++){
// p1[i]=p1[i-1]*bas1;
// p2[i]=p2[i-1]*bas2;
//
// }
//}
//void Hash(){
// _hash[0][0]=_hash[0][1]=_hash[1][0]=0;
// for(int i=1;i<=n;i++){ //前缀和
// for(int j=1;j<=m;j++){
// _hash[i][j]=_hash[i][j-1]*bas1+a[i][j]-'a';
// }
// }
// for(int i=1;i<=n;i++){ //二维前缀和
// for(int j=1;j<=m;j++){
// _hash[i][j]+=_hash[i-1][j]*bas2;
// }
// }
//
//}
int t;
int n,c,a;
int dp[2][11];
int main(){
cin>>t;
while (t--) {
memset(dp, 0, sizeof(dp));
cin>>n;
int ans=0;
for(int i=0;i<n;i++){
cin>>c>>a;
for(int j=1;j<=10;j++){
if(a!=j){
dp[c][a]=max(dp[c][a],dp[c^1][j]+1);
}
}
ans=max(ans,dp[c][a]);
}
cout<<ans<<endl;
}
}