51Nod1101 换零钱(动归)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_42391248/article/details/85221205

dp[i]:i的换法

一共有13种物品,空间是n个。这是一个不求最大价值的01背包问题。

具体思路言语表达不出来,看代码应该可以get到。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
const int mod=1e9+7; 
int dp[100005];
int t[13]={1,2,5,10,20,50,100,200,500,1000,2000,5000,10000};
int main()
{
	int n,i,j;
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	cin>>n;
	for(i=0;i<13;i++)
	{
		if(t[i]>n)
			break;
		for(j=t[i];j<=n;j++)
			dp[j]=(dp[j]+dp[j-t[i]])%mod;
	}
	cout<<dp[n]<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42391248/article/details/85221205
今日推荐