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;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有