Sdut 1223-Find Change (DP)

Source: Internet
Author: User

Topic Link: Click to open the link

It's still a coin problem. Just one more restriction is that the number of coins that make up n is not more than 100. Consider DP, you can add a dimension on a one-dimensional basis, that is, set dp[i][j] for the coins used for I represent the number of types of J.

Dp[i][j]=dp[i][j]+dp[i-1][j-v[k]], is still the type of enumeration coins.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1<<12#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int> #define ull unsigned long lon Gusing namespace Std;int n,dp[101][251];int v[]={1,2,5,10,20,50,100};void solve () {memset (dp,0,sizeof (DP));DP [0][0]= 1;for (int i=0;i<7;i++) for (int. num=1;num<=100;num++) for (int j=v[i];j<=n;j++) Dp[num][j]+=dp[num-1][j-v[i] int ans=0;for (int i=0;i<=100;i++) ans+=dp[i][n];p rintf ("%d\n", ans);} int main () {while (~SCANF ("%d", &n) &&n) solve ();    return 0;}


Sdut 1223-Find Change (DP)

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.