Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

문제 > 단계별로 풀어보기 > 19. 조합론

https://www.acmicpc.net/step/61

  • (2023.07.12) - C++

List

※ Note

   - All the codes of any language for the same problem have basically the same result.
   - Typical headers like the below are basically skipped, but they are noted seperately when theere are any additional line.
     · C++ : #include <iostream> #define endl '\n'; using namespace std;

5
20
Answer : C++ (2023.07.12)
int main()
{
    // Input
    int n;
    cin >> n;

    // Output
    int ans = n * n - n;                                    // do not need to use combination
    cout << ans << endl;

    return 0;
}

맞았습니다!!

2
4
Answer : C++ (2023.07.12)
int main()
{
    // Input
    int n;
    cin >> n;

    // Operate
    int ans = 1;
    while (n--) ans *= 2;

    // Output
    cout << ans << endl;

    return 0;
}

맞았습니다!!

10
3628800
Answer : C++ (2021.07.26)
int factorial(int n)
{
    if (n <= 1) return 1;

    return n * factorial(n - 1);
}
int main()
{
    int N;
    cin >> N;

    cout << factorial(N) << endl;

    return 0;
}

맞았습니다!!

5 2
10
Answer : C++ (2023.07.12)
int main()
{
    // Input
    int n, k;
    cin >> n >> k;

    // Operate
    int ans = 1;
    int k2 = k;
    for (int i = 0; i < k; i++) ans *= n--;
    for (int i = 0; i < k2; i++) ans /= k--;

    // Output
    cout << ans << endl;

    return 0;
}

맞았습니다!!

3
2 2
1 5
13 29
1
5
67863915
Answer : C++ (2023.07.12)
int main()
{
    int t;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        // Input
        int n, m;
        cin >> n >> m;

        // Operate : mCn
        long long ans = 1;
        for (int j = 1; j <= n; j++)                        // j must start from 1, not 0
        {
            ans *= m--;
            ans /= j;
        }

        // Output
        cout << ans << endl;
    }

    return 0;
}

맞았습니다!!