357 - Let Me Count The Ways
[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;
}
补充:软件开发 , C++ ,