n元人民币换成1元、2元、5元的零钱,请计算共有多少种兑换方法?
分析:
典型完全背包,零钱无数,只有取不取的情况。
源代码:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll t=0;
void solve()
{
ll n;
cin>>n;
ll bag=n;
ll num[3]={1,2,5};
vector<ll> dp(bag+1,0);
dp[0]=1;
for(ll i=0;i<3;i++)
{
for(ll j=num[i];j<=bag;j++)
{
dp[j]+=dp[j-num[i]];
}
}
cout<<dp[bag];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t=1;
while(t--)
solve();
return 0;
}