Sicily 14184. Incognito

14184. Incognito

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Spies use attributes to disguise themselves to make sure that they are not recognized. For example, when putting on sunglasses, a spy suddenly looks completely different and cannot be recognized anymore. Every combination of attributes gives a different appearance, but not all combinations are possible. For example, a hat and a turban are both headgear and cannot be used at the same time. Given the list of available attributes, compute how many distinct disguises can be made.

Input

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with an integer n (0 ≤ n ≤ 30): the number of available attributes.
  • n lines with two space-separated strings: the name and the category of the attribute. All strings consist of at least 1 and at most 20 lowercase letters. Within a test case all names are distinct.

Output

Per test case:

  • one line with an integer: the number of possible distinct disguises that can be made with the given attributes, such that at most one attribute from each category is used.

Sample Input

2
3
hat headgear
sunglasses eyewear
turban headgear
3
mask face
sunglasses face
makeup face

Sample Output

5
3

Problem Source

2015年每周一赛第七场

#include <iostream>
#include <map>
#include <string>
using namespace std;

int n;
int ans;
map<string, int> m;

int main() {

	int caseNum;
	cin >> caseNum;

	while (caseNum--) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			string s;
			cin >> s >> s;
			if (m.find(s) == m.end()) m[s] = 1;
			else m[s]++;
		}
		ans = 1;
		for (map<string, int>::iterator iter = m.begin(); iter != m.end(); iter++) {
			ans *= iter->second + 1;
		}
		cout << ans - 1 << endl;
		m.clear();
	}

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值