728x90
반응형
패션왕 신해빈 문제는 경우의 수를 이용한 문제입니다. (같은 종류의 개수 + 1) 항들의 곱에 -1을 한 값이 옷을 입을 수 있는 경우의 수가 됩니다.
작성한 코드는 다음과 같습니다.
#include<stdio.h>
#include<string.h>
int T;
int n;
char temp[100];
char clothes[300][100];
char cnt[300];
int limit;
int result = 1;
int k;
int main(void) {
scanf("%d", &T);
for (int i = 0; i < T; i++) {
scanf("%d", &n);
result = 1;
limit = 0;
for (int j = 0; j < 2*n; j++) {
scanf("%s", temp);
if (j % 2 == 1) {
for (k = 0; k < limit; k++) {
if (strcmp(&clothes[k][0], temp) == 0) {
cnt[k]++;
break;
}
}
if (k == limit) {
strcpy(&clothes[limit][0],temp);
cnt[limit] = 0;
cnt[limit]++;
limit++;
}
}
}
for (int j = 0; j < limit; j++) {
result = result * (cnt[j]+1);
}
printf("%d\n", result - 1);
}
}
문제의 지문은 다음의 링크에서 확인할 수 있습니다.
728x90
반응형
'전공 > Problem Solving' 카테고리의 다른 글
[알고리즘/문제풀이/BOJ 2004] 조합 0의 개수 (0) | 2021.07.10 |
---|---|
[알고리즘/문제풀이/BOJ 1676번] 팩토리얼 0의 개수 (0) | 2021.07.10 |
[알고리즘/문제풀이/BOJ 1010번] 다리 놓기 (0) | 2021.07.10 |
[알고리즘/문제풀이/BOJ 11051번] 이항 계수 2 (0) | 2021.07.10 |
[알고리즘/문제풀이/BOJ 3036번] 링 (0) | 2021.07.10 |