标签:tor 16px similar 区间 output dfs 个数 read namespace
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Output
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #define lo long long using namespace std; int a[23]; lo dp[23][23][3011]; inline long long read() { register long long ans=0,f=1;char ch=getchar(); while(!isdigit(ch)) {if(ch==‘-‘) f=-1;ch=getchar();} while(isdigit(ch)) {ans=ans*10+ch-‘0‘;ch=getchar();} return ans*f; } lo dfs(int wi,int mid,int v,bool lim) { if(wi<1) return v==0; if(!lim&&dp[wi][mid][v]>-1) return dp[wi][mid][v]; int o=lim? a[wi]:9; lo ans=0; for(int i=0;i<=o;i++) ans+=dfs(wi-1,mid,v+(wi-mid)*i,lim&&i==a[wi]); if(!lim) dp[wi][mid][v]=ans; return ans; } lo sol(lo x) { if(x<0) return 0; int w=0;lo ans=0; while(x) { a[++w]=x%10; x/=10; } for(int i=1;i<=w;i++) ans+=dfs(w,i,0,1); return ans-w+1; ////全是0的情况被多算了 } int main() { int t;lo l,r; t=read(); memset(dp,-1,sizeof(dp)); while(t--) { l=read();r=read(); printf("%lld\n",sol(r)-sol(l-1)); } return 0; }
标签:tor 16px similar 区间 output dfs 个数 read namespace
原文地址:http://www.cnblogs.com/charlotte-o/p/7612663.html