1. 程式人生 > >UVA 147 Dollars (完全揹包)

UVA 147 Dollars (完全揹包)

#include<bits/stdc++.h>
using namespace std;

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
const int  maxn =5e4+5;
const int mod=1e9+7;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///把單位全部統一一下進行完全揹包轉換。
int c[11]={10000,5000,2000,1000,500,200,100,50,20,10,5};
char s[10];
ll ans[maxn];
int main()
{
    ans[0]=1;
    for(int i=0;i<11;i++)
        for(int j=maxn-1;j>=0;j--)
            for(int k=1;j-k*c[i]>=0;k++)
                 ans[j]+=ans[j-k*c[i]];
    while(scanf("%s",s))
    {
        int n=0,len=strlen(s);
        for(int i=0;i<len;i++)
        {
            if(s[i]=='.') continue;
            n=n*10+s[i]-'0';
        }
        if(!n) break;

        ll dig=0,tp=ans[n];
        while(tp) tp/=10,dig++;

        for(int i=0;i+len<6;i++) printf(" ");  printf("%s",s);///輸出格式技巧
        for(int i=0;i+dig<17;i++) printf(" ");   printf("%lld\n",ans[n]);
    }
    return 0;
}