SGU 390-tickets (Digital DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.