dp+ High Precision URAL 1036 Lucky Tickets

Source: Internet
Author: User
Tags mul

Topic Portal

1 /*2 Test Instructions: The conversion is to find the number of n digits, the sum of the scheme of S/23 dp+ High precision: State transfer equation: dp[cur^1][k+j] = Dp[cur^1][k+j] + dp[cur][k];4 High Precision Direct take Jayye:)5 rules for XOR operations:6 0⊕0=0,0⊕1=17 1⊕0=1,1⊕1=08 formula: Same take 0, different take 19 */Ten#include <cstdio> One#include <cstring> A#include <string> -#include <iostream> -#include <algorithm> the using namespacestd; -  - Const intNumlen =1005; - Const intNumbit =4; + Const intAddbit =10000; - Const intMAXN = Numlen/numbit +Ten; +  A structBign { at     intLen, S[numlen]; - bign () { -memset (s),0,sizeof(s)); -Len =1; -     } -Bign (intNUM) {* This=num;} inBign (Const Char*num) {* This=num;} -Bignoperator= (Const intnum) { to         CharS[numlen]; +sprintf (s),"%d", num); -* This=s; the         return* This; *     } $Bignoperator= (Const Char*num) {Panax Notoginseng         intClen =strlen (num); -          while(Clen >1&& num[0] =='0') num++, clen--; theLen =0; +          for(inti = clen-1; I >=0; I-=numbit) { A             inttop = min (Numbit, i+1), Mul =1; theS[len] =0; +              for(intj =0; J < top; J + +) { -S[len] + = (num[i-j]-'0')*Mul; $Mul *=Ten; $             } -len++; -         } the deal (); -         return* This;Wuyi     } the     voiddeal () { -          while(Len >1&&!s[len-1]) len--; Wu     } -Bignoperator+ (ConstBign &a)Const { About bign ret; $Ret.len =0; -         inttop = max (len, a.len), add =0; -          for(inti =0; Add | | i < top; i++) { -             intnow =add; A             if(I < len) Now + =S[i]; +             if(I < A.len) Now + =A.s[i]; theret.s[ret.len++] = now%Addbit; -Add = now/Addbit; $         } the         returnret; the     } theBignoperator* (ConstBign &a)Const { the bign ret; -Ret.len = Len +A.len; in          for(inti =0; i < Len; i++) { the             intPre =0; the              for(intj =0; J < A.len; J + +) { About                 intnow = S[i]*a.s[j] +Pre; thePre =0; theRET.S[I+J] + =Now ; the                 if(Ret.s[i+j] >=addbit) { +Pre = ret.s[i+j]/Addbit; -RET.S[I+J]-= pre*Addbit; the                 }Bayi             } the             if(pre) Ret.s[i+a.len] =Pre; the         } - ret.deal (); -         returnret; the     } the}dp[2][1005]; theistream&operator>> (IStream &inch, Bign &x) { the     strings; -     inch>>s; thex =s.c_str (); the     return inch; the }94ostream&operator<< (Ostream & out,ConstBign &x) { theprintf"%d", x.s[x.len-1]); the      for(inti = x.len-2; I >=0; i--) printf ("%04d", X.s[i]); the     return  out;98 } About  - intMainvoid)//URAL 1036 Lucky Tickets101 {102     //freopen ("w.in", "R", stdin);103 104     intN, S; the      while(SCANF ("%d%d", &n, &s) = =2)106     {107         if(S &1) {puts ("0");Continue;}108 109dp[0][0] =1; the         intCur =0;111          for(intI=1; i<=n; ++i) the         {113              for(intj=0; j<=s/2; ++J) dp[cur^1][J] =0;  the              for(intj=0; j<=9; ++j) the             { the                  for(intk=0; k+j<=s/2; ++k)117dp[cur^1][K+J] = dp[cur^1][K+J] +Dp[cur][k];118             }119Cur ^=1; -         }121 122cout << dp[cur][s/2] * dp[cur][s/2] <<Endl;123     }124  the     return 0;126}

dp+ High Precision URAL 1036 Lucky Tickets

Related Article

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.