본문 바로가기

분할 정복을 이용한 거듭제곱/다항식 거듭제곱

(3)
백준 10961번: School canteen (Kitamasa) https://www.acmicpc.net/problem/10961 10961번: School canteen On the standard input, you will find a single line containing three space-separated integers: n, ℓ, and k. Here n is the number of days (0 ≤ n ≤ 2,000,000,000), ℓ the impatience of the students (the number of repeats of a single meal, which causes www.acmicpc.net 이전 포스팅에서 $A_{N}$을 kitamasa법을 통해 구하는 방법에 대한 포스팅입니다. 우선 점화식을 다시 가져오면 다음과 같습..
백준 27308번: 창호의 유학 준비 https://www.acmicpc.net/problem/27308 27308번: 창호의 유학 준비 재우가 준 리스트의 단어가 각각 A, B, C이고 이 중 A, B가 Well-Known 단어라고 했을 때, 가능한 전체 경우를 문자열로 나타내면 AB, AC, BA, BC, CA, CB, CC로 그 경우의 수는 $7$가지이다. www.acmicpc.net 문제가 묻는 것은 간단해보이지만, 점화식을 이끌어내기가 생각보다는 힘들었습니다. 저는 처음에 state가 너무 많이 나와서 점화식을 유도하는 부분에서 에디토리얼을 보고 배웠습니다. 제가 틀렸던 접근은 $n$번의 공부를 했을 때 마지막으로 공부한 단어가 well-known인지 아닌지, 그리고 well-known이라면 몇 번 반복됐었는지에 따라 상태를 나누고..
Kitamasa 정답 코드 모음 복잡도 - 제목1 문제번호 - 속도 선형점화식 문제 중 행렬 곱으로도 통과하지만, kitamasa법을 사용했을 때 실행속도에서 이득을 본 문제들입니다. O(N^2) 백준 17272 - 8ms #include #include #include #define mod 1000000007 typedef long long element; typedef element* poly; // polynomial = sum poly[i] * x^i poly multiply_polynomial(poly A, int degree_A, poly B, int degree_B); poly remainder_polynomial(poly A, int degree_A, poly B, int degree_B, int* degree_resul..