수학3 [백준 C++] 16565번: N포커 1. 문제https://www.acmicpc.net/problem/16565 2. 알고리즘 분류수학다이나믹 프로그래밍조합론포함 배제의 원리 3. 소스 코드#include #define MOD 10007using namespace std;int N;int Combination[53][53];// 조합 계산 함수int cal_combination(int n, int r) { if (Combination[n][r]) return Combination[n][r]; // 이전에 계산해놓은 값이 있으면, 바로 반환 else if (n == r || r == 0) Combination[n][r] = 1; // n=r 이거나, r = 0일 때, 1 반환 else { Combination[n][r] = cal_com.. 2024. 9. 5. [백준 C++] 9527번: 1의 개수 세기 1. 문제 https://www.acmicpc.net/problem/9527 9527번: 1의 개수 세기 두 자연수 A, B가 주어졌을 때, A ≤ x ≤ B를 만족하는 모든 x에 대해 x를 이진수로 표현했을 때 1의 개수의 합을 구하는 프로그램을 작성하시오. 즉, f(x) = x를 이진수로 표현 했을 때 1의 개수라 www.acmicpc.net 2. 알고리즘 분류 수학 누적 합 비트마스킹 3. 소스 코드 #include #define MAX 55 using namespace std; long long A, B; long long power[MAX]; // 1 ~ x까지 모든 수의 1의 개수의 합 계산 함수 long long calculate(long long x) { long long ret = x &.. 2024. 4. 11. [백준 C++] 11444번: 피보나치 수 6 1. 문제 https://www.acmicpc.net/problem/11444 11444번: 피보나치 수 6 첫째 줄에 n이 주어진다. n은 1,000,000,000,000,000,000보다 작거나 같은 자연수이다. www.acmicpc.net 2. 알고리즘 분류 수학 분할 정복을 이용한 거듭제곱 3. 소스 코드 #include #include using namespace std; typedef vector matrix; int MOD = 1000000007; // 행렬 곱셈 정의 matrix operator*(matrix& a, matrix& b) { matrix temp(2, vector(2)); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) .. 2023. 6. 9. 이전 1 다음