POJ Dollar Dayz USD Holiday (full backpack, regular + large number)

Source: Internet
Author: User
Tags dayz

Test instructions: Given the amount of money owned by the integers n and k,n, K represents a K tool, the price of which is 1~k. Find out how many ways to buy the N-ary.

Idea: K maximum 100, the number is too large, to use a large number. Other basic and complete backpacks are the same.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intb=1005, n= Max;7 intcoin[ -], N, K;8 9 structbign {//please set the constant n as the length of the buffer and the maximum integer first. Ten     intlen, sex; One     intS[n]; A  -Bign () {//Create a new large number -          ThisLen =1; the          ThisSex =0; -memset (s),0,sizeof(s)); -     } -Bign (intNumber) {* This= number;}//creates a large number, initialized with an integral type +Bign (Const Char* Number) {* This= number;}//creates a large number, initialized with a string -  +     void operator= (Const Char*number) {//overload equals equal to a string A         intBegin =0; atLen =0; -Sex =1; -         if(Number[begin] = ='-') { -Sex =-1; -begin++; -         } in         Else if(Number[begin] = ='+') -begin++; to  +          for(intj = begin; NUMBER[J]; J + +) -s[len++] = number[j]-'0'; the     } *  $Bignoperator= (intNumber) {//overload equals equal to an integral typePanax Notoginseng         CharStr[n];//notice here that n, to set a buffer to be used outside.  -sprintf (str,"%d", number); the* This=str; +         return* This; A     } the  + bign Change (bign cur) { - bign now; $now =cur; $          for(inti =0; i < Cur.len; i++) -Now.s[i] = cur.s[cur.len-i-1]; -         returnNow ; the     } - Wuyi     voidDelzore () {//remove the leading 0. theBign now = Change (* This); -          while(Now.s[now.len-1] ==0&& Now.len >1) { Wunow.len--; -         } About* This=Change (now); $     } -  -     voidPut () {//The output value.  - Delzore (); A         if(Sex <0&& (len! =1|| s[0] !=0)) +cout <<"-"; the          for(inti =0; i < Len; i++) -cout <<S[i]; $     } the  theBignoperator+ (ConstBign &cur) {//can only be large number operator large number the bign sum, a, B; theSum.len =0; -A = A.change (* This); inb =b.change (cur); the  the          for(inti =0, G =0; G | | I < A.len | | i < B.len; i++){ About             intx =G; the             if(I < A.len) x + =A.s[i]; the             if(I < B.len) x + =B.s[i]; thesum.s[sum.len++] = x%Ten; +g = x/Ten; -         } the         returnsum.change (sum);Bayi     } the  theBignoperator- (ConstBign &cur) {//can only be large number operator large number - bign sum, a, B; -Sum.len =Len; theA = A.change (* This); theb =b.change (cur); the  the          for(inti =0; i < B.len; i++) { -Sum.s[i] = a.s[i]-b.s[i] +Sum.s[i]; the             if(Sum.s[i] <0) { theSum.s[i] + =Ten; theSum.s[i +1]--;94             } the         } the          for(inti = B.len; i < A.len; i++) { theSum.s[i] + =A.s[i];98             if(Sum.s[i] <0) { AboutSum.s[i] + =Ten; -Sum.s[i +1]--;101             }102         }103         returnsum.change (sum);104     } the };106 107 voidcal ()108 {109dp[0]=1; the      for(intI=1; i<=n; i++) dp[i]=0;//Initialize111     intTmp=min (K,n);//K>n parts can't afford to buy the      for(intI=0; i<tmp; i++)113          for(intj=0; j+coin[i]<=n; J + +) theDp[j+coin[i]] = Dp[j+coin[i]] +Dp[j]; the  the dp[n].put ();117 }118 119 intMain () { -     //freopen ("Input.txt", "R", stdin);121      for(intI=0; i< -; i++) coin[i]=i+1;//Initialize122      while(~SCANF ("%d%d",&n,&k))123 cal ();124     return 0; the}
AC Code

POJ Dollar Dayz USD Holiday (full backpack, regular + large number)

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.