Hdu 1284 Coin Exchange Problem _ Multiple backpack

Source: Internet
Author: User
Tags cmath
Coin Exchange Issues Time limit:2000/1000ms (java/other) Memory limit:65536/32768k (java/other) Total Submission (s): accepted submission (s): the font:times New Roman | Verdana | Georgia Font size:←→ Problem DescriptionIn a country there are only 1 cents, 2 cents, 3 cents, and there are many ways to exchange money n coins. Please write a procedure to figure out how many kinds of methods are in common. InputOnly one positive integer per line n,n less than 32768. OutputFor each input, the output conversion method number. Sample Input
2934
12553
Sample Output
718831

13137761

Because it's a multiple knapsack problem, the maximum number of split numbers is removed, so you can use the parent function (which requires a table to close the timeout). )

Multi-backpack to do with the above dividing the problem is similar, only here can only use 1 2 3 of these three numbers to gather

Parent Function

#include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <queue > Using namespace std; int main () {    long long int  a1[55555];     Long long int  a2[55555];     int n ;        int i,j,k;        a1[0]=1;        a2[0]=0;        for (i=1;i<=32800;i++)        {            A1[i]=1;            a2[i]=0;       &NBSP,        for (i=2;i<=3;i++)        {    &N Bsp      for (j=0;j<=32800;j++)            for (k=0;k+j<=32800;k+=i)         {         a2[k+j]+=a1[j];         &NBSP   ;     for (int s=0;s<=32800;s++)         {              a1[s]=a2[s];                a2[s]=0;        }                    &NBSP}     & nbsp  while (cin>>n)        {           cout<<a1[n]< <endl;                  return 0; }

Backpack

#include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <queue > Using namespace std;       int main () {long long int dp[35555];       Dp[0]=1;       int i,j;       int n;       for (i=1;i<=3;i++) {for (j=1;j<=32800;j++) dp[j]+=dp[j-i];        while (cin>>n) {cout<<dp[n]<<endl; return 0; }

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.