#include <iostream>
#include <vector>
#include <bitset>
#include <deque>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
int k,n=0;
vector<vector<string> > a(18,vector<string>(3));
map<string,int> m;
bitset<55> vis;
int rec(int i){
if(i==k)return 0;
int ans1=0;
if(vis[m[a[i][0]]]||vis[m[a[i][1]]]||vis[m[a[i][2]]])return rec(i+1);
else{
vis[m[a[i][0]]]=vis[m[a[i][1]]]=vis[m[a[i][2]]]=1;
ans1=1+rec(i+1);
}
vis[m[a[i][0]]]=vis[m[a[i][1]]]=vis[m[a[i][2]]]=0;
int ans2=rec(i+1);
return max(ans1,ans2);
}
int main(){
cin>>k;
for(int i=0;i<k;i++){
ws(cin);
for(int j=0;j<3;j++){
string s;
cin>>s;
if(m.find(s)==m.end())
m.insert({s,n++});
a[i][j]=s;
}
}
cout<<rec(0)<<endl;
}
#include <vector>
#include <bitset>
#include <deque>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
int k,n=0;
vector<vector<string> > a(18,vector<string>(3));
map<string,int> m;
bitset<55> vis;
int rec(int i){
if(i==k)return 0;
int ans1=0;
if(vis[m[a[i][0]]]||vis[m[a[i][1]]]||vis[m[a[i][2]]])return rec(i+1);
else{
vis[m[a[i][0]]]=vis[m[a[i][1]]]=vis[m[a[i][2]]]=1;
ans1=1+rec(i+1);
}
vis[m[a[i][0]]]=vis[m[a[i][1]]]=vis[m[a[i][2]]]=0;
int ans2=rec(i+1);
return max(ans1,ans2);
}
int main(){
cin>>k;
for(int i=0;i<k;i++){
ws(cin);
for(int j=0;j<3;j++){
string s;
cin>>s;
if(m.find(s)==m.end())
m.insert({s,n++});
a[i][j]=s;
}
}
cout<<rec(0)<<endl;
}
Comments
Post a Comment