- #include <bits/stdc++.h>
- using namespace std;
- const int NX = 70 ;
- long long int dp[2][2][NX][NX];
- long long int vis[2][2][NX][NX];
- long long int lim , tt ;
- vector < int > inp ;
- long long int DP( int pos , int isSmall ,int isStart, int value)
- {
- if( pos == lim ) return value ;
- long long int &ret = dp[isSmall][isStart][pos][value];
- long long int &v = vis[isSmall][isStart][pos][value];
- if( v == tt ) return ret ;
- v = tt ;
- int ses = isSmall ? 9 : inp[pos];
- int i ;
- ret = 0 ;
- if( !isStart )
- for ( i = 0 ; i <= ses ; i++ )
- {
- ret += DP( pos + 1 , isSmall | i < inp[pos] ,0, (i == 0) + value );
- }
- else
- {
- for ( i = 1 ; i <= ses ; i++ )
- {
- ret += DP( pos + 1 , isSmall | i < inp[pos] ,0, (i == 0) + value );
- }
- ret += DP( pos + 1 , 1 ,1, 0 );
- }
- return ret ;
- }
- long long int Cal(long long int x )
- {
- if( x < 0 ) return 0 ;
- if( x <= 9 ) return 1 ;
- inp.clear();
- while( x )
- {
- inp.push_back(x%10);
- x/=10;
- }
- reverse(inp.begin(),inp.end());
- lim = inp.size();
- tt++;
- return DP( 0 , 0 , 1 , 0 ) + 1;
- }
- int main()
- {
- int cs , t;
- cin>>t;
- for ( cs = 1 ; cs <= t ; cs++ )
- {
- long long int n , m;
- cin>>n>>m;
- long long int ans = Cal(m) - Cal(n-1);
- printf("Case %d: %lld\n",cs,ans);
- }
- return 0;
- }
Thursday, 27 July 2017
Lightoj 1140 How Many zeros
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...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
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...
No comments:
Post a Comment