LIGHTOJ1068 investigation (Digital DP)

Source: Internet
Author: User

This question requires the number of modulo k and the number of members and modulo K equals 0.

Notice [1,231] The sum of these numbers is not more than 90 or so, and if K is greater than 90 then the result of modulo K is certainly not 0, so K is greater than 90 without solution.

Given the size of the data, the number of data groups, the state of the problem is that:

DP[I][J][K]: The number of digits for the I-mode K result is J and the number of the sum of the number of modulo k results k

Then there is the transfer equation, and the last is statistics.

Statistics part good tricky ... Half-messed with AC. Or is it too unfamiliar to this part of the digital DP.

1#include <cstdio>2#include <cstring>3 using namespacestd;4 intk,d[ One][ -][ -],pow[Ten]={1};5 intCalU (intN) {6     intres=0, pre=0, sum=0;7      for(intI=9; i>=0; --i) {8         if(i==0) for(intj=0; j<=n/pow[i]%Ten; ++j) res+=d[i][(K (pre*Ten+J) *pow[i])%K)%k][(K (sum+j)%K)%K];9         Else  for(intj=0; j<n/pow[i]%Ten; ++j) res+=d[i][(K (pre*Ten+J) *pow[i])%K)%k][(K (sum+j)%K)%K];Tenpre=pre*Ten+n/pow[i]%Ten; Onesum+=n/pow[i]%Ten; A     } -     returnRes; - } the intMain () { -      for(intI=1; i<Ten; ++i) pow[i]=pow[i-1]*Ten; -     intt,a,b; -scanf"%d",&t); +      for(intCse=1; cse<=t; ++CSE) { -scanf"%d%d%d",&a,&b,&K); +         if(k>= -){ Aprintf"Case %d:%d\n"Cse0); at             Continue;  -         } -memset (D,0,sizeof(d)); -d[0][0][0]=1; -          for(intI=0; i<Ten; ++i) ++d[1][i%k][i%K]; -          for(intlen=1; len<Ten; ++Len) { in              for(intI=0; i<k; ++i) { -                  for(intj=0; j<k; ++j) { to                     if(d[len][i][j]==0)Continue; +                      for(intk=0; k<Ten; ++K) d[len+1[(i*Ten+k)%k][(j+k)%k]+=D[len][i][j]; -                 } the             } *         } $printf"Case %d:%d\n", Cse,calu (b)-calu (A-1));Panax Notoginseng     } -     return 0; the}

LIGHTOJ1068 investigation (Digital DP)

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: 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.