标签:ring math div stream bug ref mit scan acm
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 5276 Accepted Submission(s): 2523
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <map> 10 #define ll __int64 11 #define dazhi 2147483647 12 #define bug() printf("!!!!!!!") 13 #define M 100005 14 using namespace std; 15 ll a,b; 16 ll f[30][30][2005]; 17 int bit[30]; 18 ll dp(int pos,int x,int st,int flag) 19 { 20 if(pos==0) return st==0; 21 if(st<0) return 0; 22 if(flag&&f[pos][x][st]!=-1) return f[pos][x][st]; 23 int d=flag?9:bit[pos]; 24 ll re=0; 25 for(int i=0;i<=d;i++) 26 { 27 re+=dp(pos-1,x,st+i*(pos-x),flag||i!=d); 28 } 29 if(flag) f[pos][x][st]=re; 30 return re; 31 } 32 ll fun(ll n) 33 { 34 if(n<0) return 0; 35 int len=0; 36 while(n>0) 37 { 38 bit[++len]=n%10; 39 n/=10; 40 } 41 ll ans=0; 42 for(int i=1;i<=len;i++) 43 { 44 ans+=dp(len,i,0,0); 45 } 46 return ans-len+1; 47 } 48 int main() 49 { 50 int t; 51 scanf("%d",&t); 52 memset(f,-1,sizeof(f)); 53 while(t--) 54 { 55 scanf("%I64d %I64d",&a,&b); 56 printf("%I64d\n",fun(b)-fun(a-1)); 57 } 58 return 0; 59 }
标签:ring math div stream bug ref mit scan acm
原文地址:http://www.cnblogs.com/hsd-/p/6613413.html