USACO 2.3.4 Money Systems

母牛们不但创建了他们自己的政府而且选择了建立了自己的货币系统。
[In their own rebellious way],,他们对货币的数值感到好奇。
传统地,一个货币系统是由1,5,10,20 或 25,50, 和 100的单位面值组成的。
母牛想知道有多少种不同的方法来用货币系统中的货币来构造一个确定的数值。

 
边界条件设f[0]等于1,什么累加的方法数是一,累加得0.
    f[0]←1;
    for i←1 to v do
        for j←cash to n do
            f[j]←f[j]+f[j-cash]



#include <iostream>
#include <cstring>

using namespace std;


int main()
{
    int cost[100]={0};
    int f[1000]={0};
    f[0]=1;

    int n,v;
    cin>>v>>n;

    for(int i=0;i<v;i++)
    {
        cin>>cost;
    }
    int i,j;
    for(i=0;i<v;i++)
        for(j=cost;j<=n;j++)
        {
        f[j]=f[j]+f[j-cost];
        }

    cout<<f[n];

    return 0;
}

原文地址:https://www.cnblogs.com/CKboss/p/3351106.html