목록조합론 (8)
정화 코딩

https://www.acmicpc.net/problem/29727 #include using namespace std;long long comb(int n, int r) { if (r > n) return 0; long long ans = 1; for (int i = n; i > n - r; i--) { ans *= i; } for (int i = r; i > 0; i--) { ans /= i; } return ans;}int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, xa, ya, xb, yb; cin >> n >> xa >> y..

090. LCS 2 (백준 9252번) https://www.acmicpc.net/problem/9252 import sysinput = sys.stdin.readlinestr1 = input().strip()str2 = input().strip()len1 = len(str1)len2 = len(str2)dp = [[0 for _ in range(len2 + 1)] for _ in range(len1 + 1)]memo = [[0 for _ in range(len2 + 1)] for _ in range(len1 + 1)]for i in range(1, len1 + 1): for j in range(1, len2 + 1): if str1[i - 1] == str2[j - 1]: ..

A. 베라의 패션 (백준 15439번) https://www.acmicpc.net/problem/15439 #python import sys input = sys.stdin.readline n = int(input()) ans = n * (n - 1) print(ans) (정답) C. 격자상의 경로 (백준 10164번) #python import sys input = sys.stdin.readline n, m, k = map(int, input().split()) dp = [[0 for _ in range(n + m - 1)] for _ in range(n + m - 1)] ans = 0 dp[0][0] = 1 for i in range(1, n + m - 1): dp[i][0] = dp[i][i] = ..

080. 조약돌 꺼내기 (백준 13251번) https://www.acmicpc.net/problem/13251 import sys input = sys.stdin.readline m = int(input()) # 조약돌 색 종류 color = list(map(int, input().split())) # 색 별 조약돌의 수 k = int(input()) # 뽑는 조약돌의 수 n = sum(color) # 전체 조약돌 수 ans = 0 for x in color: if x >= k: tmp = 1 for i in range(k): tmp *= ((x - i) / (n - i)) ans += tmp print(ans) 오잉 다이나믹도 아니고 조합 구할 필요도 없는 문제였잖아..???? 문제 풀기 전에 생각을..

A. 다이나믹이 뭐예요? (백준 14494번) https://www.acmicpc.net/problem/14494 #python from sys import stdin # 점화식 : dp[i][j] = dp[i-1][j] + dp[i][j-1] + dp[i-1][j-1] mod = 1000000007 n, m = map(int, stdin.readline().split()) # n 가로 m 세로 dp = [[0 for _ in range(n + 1)] for _ in range (m + 1)] for i in range(1, n + 1): dp[1][i] = 1 for i in range(2, m + 1): dp[i][1] = 1 for j in range(2, n + 1): dp[i][j] = (dp[..

10-1. 조합 알아보기 076. 이항 계수 1 (백준 11050번) https://www.acmicpc.net/problem/11050 from sys import stdin n, k = map(int, stdin.readline().split()) dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)] dp[0][0] = 1 for i in range(1, n + 1): dp[i][0] = dp[i][i] = 1 for j in range(1, i): dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] print(dp[n][k]) 예전에 팩토리얼로 풀었던 문제. 이렇게 점화식을 이용해서 전체 테이블을 다 채워서 푸는 풀이로는 처음 풀..

9/1. 이항 계수 1 (백준 11050번) https://www.acmicpc.net/problem/11050 #python import sys def fact(num) : ans = 1 for i in range(1, num+1) : ans *= i return ans n, k = map(int, sys.stdin.readline().split()) ans = fact(n) / (fact(k) * fact(n-k)) print(int(ans)) 저번에 풀었던 문제이지만 저번에 풀 때는 함수를 만들어서 하지 않았기 때문에, 이번에는 함수를 만들어서 활용하는 방법으로 풀어봤다. (정답) 9/3. 카드2 (백준 2164번) https://www.acmicpc.net/problem/2164 #python i..

깃허브에 코딩 문제 풀기용 레포지토리를 만들었다. 깃허브에 올리는 연습을 하기 위해... 후후 깃헙과 친해질거다!! 8/28. 직각삼각형 (백준 4153번) https://www.acmicpc.net/problem/4153 #python import sys while True : a, b, c = map(int, sys.stdin.readline().split()) if a + b + c == 0 : exit() max = c if a > max : max = a if b > max : max = b if a*a + b*b + c*c == max*max*2 : print("right") else : print("wrong") (정답) 8/28. 블랙잭 (백준 2798번) https://www.acmicp..