当前位置: 代码迷 >> 综合 >> HDU 1864 最大报销额 .
  详细解决方案

HDU 1864 最大报销额 .

热度:87   发布时间:2023-09-23 06:55:00.0

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

题目很坑!!!

是单类物品不能超出600

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double d[30+5];
//前i个最大的报销额
double P[3];
int main()
{double MaxPrice,price; int N,m;while(cin>>MaxPrice>>N&&N){memset(d,0,sizeof(d));for(int i=0;i<N;i++){cin>>m; double sum=0,p; char type; bool ok=true;memset(P,0,sizeof(P));while(m--){scanf(" %c:%lf",&type,&p);if(type!='A'&&type!='B'&&type!='C') ok=false;P[type-'A']+=p;if(P[type-'A']>600) ok=false;sum+=p;}if(sum>1000) ok=false;price=ok?sum:0;for(int j=0;j<=i;j++)d[j+1]=max(d[j+1],d[j]+price>MaxPrice?d[j]:d[j]+price);} printf("%.2f\n",d[N]);}return 0;
}