【USACO 2.3】Money Systems(dp)

2020-06-02 11:05:28 浏览数 (1)

v种货币,求有多少种组成和为n。

dp[i][j]表示前i种货币价格为j有多少种方案,dp[i][j] =dp[i-1][j-c]。

http://train.usaco.org/usacoprob2?a=jUh88pMwCSQ&S=money

代码语言:javascript复制
/*
TASK:money
LANG:C  
*/
#include<cstdio>
#include<string>
#include<algorithm>
#define ll long long
#define file(s) freopen(#s".in","r",stdin);freopen(#s".out","w",stdout)
using namespace std;
#define N 10005
int v,n;
ll dp[N]={1};
int main(){
    file(money);
    scanf("%d%d",&v,&n);
    int c;
    for(int i=1;i<=v;i  ){
        scanf("%d",&c);
        for(int j=c;j<=n;j  )
            dp[j] =dp[j-c];
    }
    printf("%lldn",dp[n]);
    return 0;
}
dp

0 人点赞