uva147 Dollars ——完全背包

August 15, 2013
Uva DP

link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 和完全背包一样的思想。 有两个trick: 没了。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[8][2] = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}};
using namespace std;
long long d[33333];
int a[11]={5,10,20,50,100,200,500,1000,2000,5000,10000};
int main(void) {
    ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    double tmp;
    while(cin>>tmp) {
        int n; 
        //n=(int)(tmp*100);
        n=(int)(0.5+tmp*100);
        n/=5;
        if(!n) break;
        memset(d,0,sizeof(d)); 
        d[0]=1;
        for (int i=0;i<11;++i) {
            for (int j=a[i]/5;j<=n;++j) {
                d[j]+=d[j-a[i]/5];
            }
        }
        printf("%6.2f%17lld\n",tmp,d[n]);
    }
    return 0;
}

o(╯□╰)o 因为精度那个东西WA了。

comments powered by Disqus