[cpp]
描述:這道題還好,相比起上一題沒有精度問題
#include <cstdio>
long long s[30010];
int v[6]= {1,5,10,25,50};
void solve()
{
s[0]=1;
for(int i=0; i<5; i++)
for(int j=v[i]; j<30010; j++)
s[j]+=s[j-v[i]];
}
int main()
{
int n;
solve();
// freopen("a.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
if(s[n]==1) printf("There is only 1 way to produce %d cents change.\n",n);
else printf("There are %lld ways to produce %d cents change.\n",s[n],n);
}
return 0;
}
描述:這道題還好,相比起上一題沒有精度問題
#include <cstdio>
long long s[30010];
int v[6]= {1,5,10,25,50};
void solve()
{
s[0]=1;
for(int i=0; i<5; i++)
for(int j=v[i]; j<30010; j++)
s[j]+=s[j-v[i]];
}
int main()
{
int n;
solve();
// freopen("a.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
if(s[n]==1) printf("There is only 1 way to produce %d cents change.\n",n);
else printf("There are %lld ways to produce %d cents change.\n",s[n],n);
}
return 0;
}