link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83

和完全背包一样的思想。

有两个trick:

  1. 浮点数转化成整数的时候,注意精度。
  2. 因为题目中说了都是5的倍数,所以可以都除以5.

没了。

 #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[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
long long d[];
int a[]={,,,,,,,,,,};
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*);
n/=;
if(!n) break;
memset(d,,sizeof(d));
d[]=;
for (int i=;i<;++i) {
for (int j=a[i]/;j<=n;++j) {
d[j]+=d[j-a[i]/];
}
}
printf("%6.2f%17lld\n",tmp,d[n]);
}
return ;
}

o(╯□╰)o

因为精度那个东西WA了。

05-04 04:46