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

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

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

/*
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("%lld\n",dp[n]);
    return 0;
}

 

 

 

  

相关文章:

  • 2022-02-13
  • 2021-12-07
  • 2021-05-31
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-11-14
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案