您的位置:首页 > 其它

UVA 147 Dollars(完全背包)

2017-08-13 23:20 459 查看
和uva647基本一样,注意精度

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

const int MAXN = 33333;
int w[11] = {5,10,20,50,100,200,500,1000,2000,5000,10000};
int W;
long long dp[MAXN];

void solve()
{
memset(dp,0,sizeof(dp));
dp[0] = 1;
for(int i = 0; i < 11; ++i)
{
for(int j = w[i]; j <= W; ++j)
{
dp[j] += dp[j-w[i]];
}
}
}

int main()
{
double money;
while(cin >> money && money != 0.0)
{
W = int(money*100.0+0.5);
solve();
cout.width(6);
cout << fixed << setprecision(2) << money;
cout.width(17);
cout << dp[W] <<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: