- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- ll DP[2][11][82][82];
- int lim, tt, k;
- vector<int>inp;
- ll dp(int pos,int issmall,int digrem,int numrem){
- if(pos == lim){
- return !(digrem+numrem);
- }
- if(DP[issmall][pos][digrem][numrem]!= -1){
- return DP[issmall][pos][digrem][numrem];
- }
- ll ret = 0;
- int mx = (issmall)? 9:inp[pos];
- for(int i = 0; i <mx; i++){
- ret+= dp(pos+1, 1, (digrem+i)%k, (numrem*10+i)%k);
- }
- ret+= dp(pos+1, issmall,(digrem+mx)%k, (numrem*10+mx)%k);
- DP[issmall][pos][digrem][numrem] = ret;
- return ret;
- }
- int solve (int n){
- inp.clear();
- int sum= 0;
- while(n!= 0){
- sum+= n%10;
- inp.push_back(n%10);
- n = n/10;
- }
- reverse(inp.begin(), inp.end());
- lim = inp.size();
- tt++;
- return dp(0, 0, 0, 0);
- }
- int main()
- {
- ll a, b;
- int ts;
- cin>>ts;
- for(int i = 1; i <=ts; i++){
- cin>>a>>b>>k;
- ll ans;
- if(k >= 82 ){
- cout<<"Case "<<i<<": "<<"0"<<endl;
- }
- else if(k == 1){
- cout<<"Case "<<i<<": "<<b-a+1<<endl;
- }
- else{
- memset(DP, -1, sizeof(DP));
- ans = solve(b);
- memset(DP, -1, sizeof(DP));
- ans-= solve(a-1);
- cout<<"Case "<<i<<": "<<ans<<endl;
- }
- }
- return 0;
- }
Thursday 27 July 2017
Lightoj 1068 Investigation
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment