Uva674-Coin Change (full backpack)

Source: Internet
Author: User

Uva674-Coin Change (full backpack)

Question: uva674-Coin Change (full backpack)


Give 1 5 10 25 50 coins with the nominal value of 5, then give N, and ask the number of different ways to make up N with the money. 1 5 and 5 1 indicate that the order is the same.


Solution: A full backpack. State equation: dp [j] + = dp [j-v [I ]];


Code:

#include 
 
  #include 
  
   const int N = 5;const int maxn = 8000;typedef long long ll;int n;int v[N] = {1, 5, 10, 25, 50};//ll dp[maxn][N];ll d[maxn];/*void init () {memset (dp, -1, sizeof (dp));//have not been searchfor (int i = 0; i < N; i++) dp[0][i] = 1;}*//*ll DP (int x, int k) {ll& ans = dp[x][k];if (ans != -1)return ans;ans = 0;for (int i = k; i < N && x >= v[i]; i++)ans += DP(x - v[i], i); return ans;}*/int main () {//init();memset (d, 0, sizeof (d));d[0] = 1;for (int i = 0; i < N; i++)for (int j = v[i]; j <= maxn; j++)d[j] += d[j - v[i]]; while (scanf ("%d", &n) != EOF) {//printf ("%lld\n", DP(n, 0));printf ("%lld\n", d[n]);}return 0;}
  
 


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.