Logo
(追記) (追記ここまで)

4180번 - Nice Prefixes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB92240.000%

문제

Consider strings formed from characters from an alphabet of size K. For example, if K = 4, our alphabet might be {a,b,c,d}, and an example string is bbcac.

For a string S, define count(S, k) to be the number of occurrences of the symbol k in S. For example, count(bbcac, b) = 2 and count(bbcac, a) = 1.

A prefix of a string S is any string obtained from S by deleting some (possibly none) of the trailing characters of S. For example, the prefixes of acb are the empty string, a, ac, and acb.

A string S has "nice prefixes" if for every prefix P of S and for every two characters k1 and k2 in the alphabet, |count(P, k1) - count(P, k2)| <= 2. For example, bbcac has nice prefixes, but abbbc does not because count(abbb, b) = 3 and count(abbb, c) = 0.

Count the number of strings of length L on an alphabet of size K that have nice prefixes. This number can be large, so print its remainder when divided by 1000000007.

입력

The input is a single line containing the two integers L and K, separated by spaces, with 1 <= L <= 1018 and 1 <= K <= 50.

출력

Output a single line containing the number of strings of length L on an alphabet of size K that have nice prefixes, modulo 1000000007.

제한

예제 입력 1

4 2

예제 출력 1

12

힌트

출처

Contest > Waterloo's local Programming Contests > 13 June, 2009 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /