hackerrank# The Coin change problem

Source: Internet
Author: User

Original title Address

Knapsack problem, nothing to say, remember to use a long long, otherwise it will explode

Code:

1#include <cmath>2#include <cstdio>3#include <vector>4#include <iostream>5#include <algorithm>6#include <cstring>7 using namespacestd;8 9 #defineMax_n 256Ten #defineMax_m 64 One  A Long LongF[max_n]; - intC[max_m]; - intm, N; the  - intMain () { -     /*Enter your code here. Read input from STDIN. Print output to STDOUT*/    -CIN >> N >>m; +      for(inti =0; I < m; i++) -CIN >>C[i]; +  AMemset (F,0,sizeof(f)); atf[0] =1; -      for(inti = m-1; I >=0; i--) -          for(intj =1; J <= N; J + +) -             if(J >=C[i]) -F[J] + = f[j-C[i]]; -  incout << F[n] <<Endl; -     return 0; to}

hackerrank# The Coin change problem

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.