Test instructions: There is a label L-r ticket, to give a passer-by, when the number of the number of votes to the sum of each digit (perhaps a person more than one ticket) not small K, only began to send to the next person, ask how many people.
Analysis: This problem is very difficult to think, refer to the question, dp[i][sum][left] length i current digit and sum before a subtree remaining and
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007; ll L,r;intk,lbit[ -],rbit[ -],used[ -][ About][1010];structnode{ll Num,left;//num can be issued, left the previous subtree remaining andNode (ll num =0, ll left =0): num (num), left (left) {} nodeoperator+=(Node B) {num+=B.num; Left=B.left; return* This; }}dp[ -][ About][1010];node DFS (intIintSumintLeftintLeintre) { if(i==0){ if(sum+left>=k)returnNode1,0); returnNode0, sum+Left ); } if(used[i][sum][left]&&!le&&!re)returnDp[i][sum][left]; intLl=le?lbit[i]:0; intRr=re?rbit[i]:9; Node A (0, left); for(intv=ll;v<=rr;++v) {a+=dfs (I-1,sum+v,a.left,le&& (V==LL),re&& (v==RR)); } if(!le&&!re) {Dp[i][sum][left]=A; Used[i][sum][left]=1; } returnA;}voidsolve () {memset (used,0,sizeof(used)); Memset (DP,0,sizeof(DP)); intlen=0; while(r) {rbit[++len]=r%Ten; R/=Ten; Lbit[len]=l%Ten; L/=Ten; } node T=dfs (Len,0,0,1,1); printf ("%i64d\n", T.num);}intMain () {scanf ("%i64d%i64d%d",&l,&r,&k); Solve ();return 0;}
SGU 390-tickets (Digital DP)