Bnu 34985 Elegant String (matrix Rapid power + dp derivation formula)

Source: Internet
Author: User

Bnu 34985 Elegant String (matrix Rapid power + dp derivation formula)

Elegant StringTime Limit: 1000 msMemory Limit: 65536KB64-bit integer IO format: % lld Java class name: MainPrev Submit Status Statistics Discuss NextWe define a kind of strings as elegant string: among all the substrings of an elegant string, none of them is a permutation of "0, 1 ,..., K ". let function (n, k) be the number of elegant strings of length n which only contains digits from 0 to k (random SIVE ). please calculate function (n, k ). inputInput starts with an integer T (T ≤ 400), denoting the number of test cases. each case contains two integers, n and k. n (1 ≤ n ≤ 1018) represents the length of the strings, and k (1 ≤ k ≤ 9) represents the biggest digit in the string. outputFor each case, first output the case number" Case # x:", And x is the case number. Then output function (n, k) mod 20140518 in this case. Sample Input
21 17 6
Sample Output
Case #1: 2Case #2: 818503
Source2014 ACM-ICPC Beijing Invitational Programming Contest

Question and code:



# Include
 
  
# Include
  
   
# Include
   
    
Using namespace std; typedef long ll; const long mod = 20140518; struct mat {ll t [10] [10]; void set () {memset (t, 0, sizeof (t) ;}} a, B; mat multiple (mat a, mat B, ll n, ll p) {ll I, j, k; mat temp; temp. set (); for (I = 0; I
    
     
> = 1; B = multiple (B, B, n, p);} return t;} void init (ll k) {B. set (); for (ll I = 0; I
     
      






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.