hdoj1864

Problem : 1864 ( 最大报销额 )     Judge Status : Accepted
RunId : 2682097    Language : G++    Author : huwenbiao
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
/***************************************************************\ *Author:Hu Wenbiao *Created Time: Sun 25 Jul 2010 03:22:16 PM CST *File Name: main.cpp *Description:01背包\***************************************************************///*========================*Head File*========================*\\#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>/*----------------------*Global Variable*----------------------*/double Q,price,a,b,c;int f[3000010],N,m,cost,V;char type;bool flag;//*=======================*Main Program*=======================*//using namespace std;int main(){    //freopen("input","r",stdin);    while(scanf("%lf%d",&Q,&N)!=EOF&&N){        V=Q*100;        memset(f,0,(1+V)*sizeof(int));        while(N--){            scanf("%d",&m);            a=b=c=0;            flag=true;            if(m==0)continue;            while(m--){                scanf(" %c:%lf",&type,&price);                if(type=='A')                  a+=price;                else if(type=='B')                  b+=price;                else if(type=='C')                  c+=price;                else                  flag=false;            }            if(a>600||b>600||c>600||a+b+c>1000)              flag=false;            if(!flag)continue;            cost=(a+b+c)*100;            for(int v=V;v>=cost;v--)              f[v]=max(f[v],f[v-cost]+cost);        }        double ans=f[V];        printf("%.2lf\n",ans/100);    }}

posted @ 2010-07-25 16:24  open source  阅读(263)  评论(0编辑  收藏