标签:acm codeforces
set<int> st[10];
int all = 1 << 10, ans = INF;
int change(char x)
{
if (x == 'B') return 0;
else if (x == 'Y') return 1;
else if (x == 'W') return 2;
else if (x == 'G') return 3;
else return 4; //R
}
void fun(int num, set<int> st[])
{
int one = 0, t[10] = {0};
for (int j = 1, ct = 0; j < all; j <<= 1, ct++)
if (num & j)
{
one++;
t[ct] = 1;
}
REP(i, 5) FF(j, 5, 10)
if (t[i] && t[j])
{
st[i].erase(j);
st[j].erase(i);
}
REP(i, 10)
if (t[i] && st[i].size() == 1)
{
st[*(st[i].begin())].erase(i);
st[i].clear();
}
int len = 0;
REP(i, 5) len += st[i].size();
if (len <= 1)
ans = min(ans, one);
}
int main()
{
int n;
char x; int y;
cin >> n;
REP(i, n)
{
cin >> x >> y;
st[change(x)].insert(y + 4);
st[y + 4].insert(change(x));
}
FF(i, 0, all)
{
set<int> tt[10];
REP(j, 10) tt[j] = st[j];
fun(i, tt);
}
WI(ans);
return 0;
}Codeforces Round #253 (Div. 2)——Borya and Hanabi,布布扣,bubuko.com
Codeforces Round #253 (Div. 2)——Borya and Hanabi
标签:acm codeforces
原文地址:http://blog.csdn.net/wty__/article/details/37908541