【解题报告】【HDOJ1864】【01背包】最大报销额

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1864

 1 #include<stdio.h>
 2 int main()
 3 {
 4     double price,sum,a,value[31],record[31];
 5     int c,t,i,j,flag,n,sa,sb,sc;
 6     char str;
 7     //freopen("1.txt","r",stdin);
 8     while(scanf("%lf%d",&price,&c)!=EOF&&c)
 9     {
10         n=0;
11         while(c--)
12         {    
13             sa=0;sb=0;sc=0;
14             sum=0;
15             flag=1;
16             scanf("%d",&t);
17             while(t--)
18             {    
19                 getchar();
20                 scanf("%c%*c%lf",&str,&a);
21                 if(str=='A') sa+=a;
22                 if(str=='B') sb+=a;
23                 if(str=='C') sc+=a;
24                 if(str<='C'&&str>='A') {}
25                 else flag=0;
26                 sum+=a;
27             }
28             if(sa>600||sb>600||sc>600) flag=0;
29             if(sum>1000) flag=0;
30             if(flag) 
31             {
32                 value[n]=sum;
33                 n++;
34             }
35             //--------
36             for(i=0;i<n;i++) record[i]=0;
37 
38             for(i=0;i<n;i++)
39             {
40                 for(j=n;j>=1;j--)
41                     if(record[j]<record[j-1]+value[i])
42                         record[j]=record[j-1]+value[i];
43             }
44         }
45 
46         for(i=n;i>=0;i--)
47         {
48             if(price>=record[i]) 
49             {
50                 printf("%.2lf\n",record[i]);
51                 break;
52             }
53         }
54         //以上已经将数据筛选出来,下面转化成01背包问题
55 
56     }
57     return 0;
58 }

 

 

posted on 2012-07-21 18:46  coding封神  阅读(140)  评论(0编辑  收藏  举报

导航