朱色虫居
Pages
Home
Featured Posts
2006/10/01
147-Dollars
/*
"Dollars"
Level:4.5
Date:2006/9/30
技巧:Dynamic programming
參357
*/
#include
#define N 11
#define M 6010
main(){
int coin[N]={1,2,4,10,20,40,100,200,400,1000,2000};
long long table[M]={0};
float cent=0.0f;
int i=0,j=0;
table[0]=1;
for(i=0;i < N;i++){ for(j=coin[i];j < M;j++) table[j]+=table[j-coin[i]]; } while(scanf("%f",¢)){ if(cent == 0.00) break; /* 浮點數做casting要很小心,最好的做法是,先轉成字串,然後用實數部分做除法, 商數再加回浮點數 */ i = (int)((cent*100+0.5)/5); /* 上傳ACM,%17I64d 要改成%17lld */ printf("%6.2f%17I64d\n",cent,table[i]); } }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment