poj 1252 Euro Efficiency

http://poj.org/problem?id=1252

题意:给出六种钱币(面值都在1-100)求出组合成1-100的最少步数和(这里可以减);

思路:完全背包;

代码:

View Code
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define mm 9999999
int dp1[2100]; //这里刚开始开到200,会WA,要开大一点
int a[7];
double ans = 0;
int ma = 0;
int main()
{
    int w = 0;
    scanf("%d",&w);
    while(w--)
    {
        ma = 0;
        ans = 0;
        for(int i = 1;i <= 6; ++i)
        scanf("%d",&a[i]);
            fill_n(dp1,2005,mm);
            dp1[0] = 0;
        for(int i = 6;i >= 1; --i)
        for(int t = a[i];t <= 2000;++t)
        if(dp1[t] > dp1[t-a[i]]+1)
        dp1[t] = dp1[t-a[i]]+1;
        for(int i = 1;i <= 100; ++i)
        {
            int temp = mm;
        for(int j = 0;j <= 1900; ++j)
        if(temp > dp1[j+i] + dp1[j])
        temp = dp1[j+i] + dp1[j];
        if(temp > ma)
        ma = temp;
        ans = ans + temp;
        }
        printf("%.2f %d\n",ans/100,ma);
    }
}
posted @ 2012-04-13 21:22  LT-blogs  阅读(273)  评论(0编辑  收藏  举报