티스토리 뷰
https://www.acmicpc.net/problem/9375
map을 이용해서 옷 종류마다 개수를 세준다. 그리고 모든 가능한 경우는 (a+1)*(b+1)* ... *(z+1)와 같이 이항계수의 성질을 이용해서 구할 수 있다. 마지막에 옷을 안 입는 경우를 하나 빼준다.
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 | #include <iostream> #include <map> #include <string> using namespace std; int main() { int t,n; scanf("%d",&t); while(t--) { map<string,int> m; scanf("%d",&n); while(n--) { string a,b; cin>>a>>b; m[b]++; } int ans=1; for(auto it=m.begin();it!=m.end();it++) ans*=it->second+1; printf("%d\n",ans-1); } return 0; } | cs |
'Algorithm > BOJ' 카테고리의 다른 글
2583 영역 구하기 (0) | 2018.07.09 |
---|---|
1924 2007년 (0) | 2018.07.09 |
9009 피보나치 (0) | 2018.07.03 |
15789 CTP 왕국은 한솔 왕국을 이길 수 있을까? (0) | 2018.06.27 |
2688 줄어들지 않아 (0) | 2018.06.08 |