HDU Coin Exchange question (full backpack?) ) __DP

Source: Internet
Author: User

Time limit:1000ms Memory limit:32768kb 64bit IO format:%i64d &%i64u
Submit

Status
Description
In 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.

Input
Only one positive integer per line n,n less than 32768.

Output
For each input, the output conversion method number.

Sample Input
2934
12553

Sample Output
718831
13137761

Although this is a knapsack problem, but the Vegetableschinese still want to jump out of the backpack, from the traditional thinking DP way to start thinking.
The first thought immediately is f[i]=f[i-1]+f[i-2]+f[i-3] is obviously wrong, so there will be a lot of repetition, the value is very large.
So it can be found that the different solutions in the final analysis of the number of each coin is not the same. This is the question of choosing a few coins for each type of coin, so it can be linked to the backpack. For each kind of coin can choose very many, this is the complete backpack. F[n] Represents the number of options that n can be exchanged for money.
F[n] The recursion a bit clever qwq at the beginning did not think out ...

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MEM (Array) memset (array,0,sizeof (array)
long  f[40000];
int e,f,n,t;
int main () {
    //freopen ("In.txt", "R", stdin);
    MEM (f);
    F[0]=1;
    for (int i=1;i<=3;i++) for
        (int j=i;j<=32768;j++)
            f[j]+=f[j-i];
    while (cin>>n)
    cout<<f[n]<<endl;
    return 0;
}

Of course, Baidu after this problem there are other solutions Qwq

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.