1. 활동 내역

1) 알고리즘 문제해결(조합 및 순열)

이 문제는 주어진 조건에 따라 조합과 순열을 계산하는 알고리즘을 구현하는 것이다. 이 알고리즘은 특정 조건을 만족하는 경우의 수를 구하는 데 사용되며, 조합과 순열의 계산을 포함한다.

풀어본 문제: 비밀번호 찾기

#include <stdio.h>
long long comb(int a, int b) {
    if (b > a) return 0;
    if (b * 2 > a) b = a - b;
    if (b == 0) return 1;

    long long res = a;
    for (int i = 2; i <= b; i++) {
        res *= (a - i + 1);
        res /= i;
    }
    return res;
}

long long perm(int a, int b) {
    if (b > a) return 0;
    long long res = 1;
    for (int i = 0; i < b; i++) {
        res *= (a - i);
    }
    return res;
}

int main() {
    int n, m, x, y;
    scanf("%d %d %d %d", &n, &m, &x, &y);

    int setPW = 0;
    int noneSetPW = 0;

    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);

        if (a != 0) {
            setPW++;
        } else {
            noneSetPW++;
        }
    }

    n -= setPW;

    long long result = 1;

    if (noneSetPW > 0) {
        result *= comb(n, noneSetPW) * perm(noneSetPW, noneSetPW);
    }

    n -= noneSetPW;

    if (n > 0) {
        result *= perm(9 - (setPW + noneSetPW), n);
    }

    printf("%lld\\n", result * x + (result - 1) / 3 * y);

    return 0;
}

조합 함수(comb):

순열 함수(perm):

메인 함수(main):