전공/Problem Solving

[알고리즘/문제풀이/BOJ 9375번] 패션왕 신해빈

caneo 2021. 7. 10. 16:13
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);
	}
}

문제의 지문은 다음의 링크에서 확인할 수 있습니다.

https://www.acmicpc.net/problem/9375

728x90
반응형