hdu 1864 最大报销额 (DP)
题目意思:
01背包:
dp[j]=dp[j-v[i]]+v[i]
C++:
[csharp]
#include"stdio.h"
#include"string.h"
int dp[3000001];
int v[31],cnt;
int main()
{
int i,j,n;
double q,t;
int Q,N;
while(scanf("%lf%d",&q,&N),N)
{
cnt=0;
Q=(int)(q*100.0);
for(i=0;i<N;i++)
{
scanf("%d",&n);
int A,B,C,f;
A=B=C=0;
f=1;
for(j=0;j<n;j++)
{
char c;
scanf(" %c:%lf",&c,&t);
getchar();
if(c=='A')A+=(int)(t*100);
else if(c=='B')B+=(int)(t*100);
else if(c=='C')C+=(int)(t*100);
else f=0;
if(A+B+C>100000||A>60000||B>60000||C>60000)f=0;
}
if(f)v[cnt++]=A+B+C;
} www.zzzyk.com
memset(dp,0,sizeof(dp));
for(i=0;i<cnt;i++)
{
for(j=Q;j>=v[i];j--)
{
if(dp[j]<dp[j-v[i]]+v[i])
dp[j]=dp[j-v[i]]+v[i];
}
}
printf("%.2f\n",(double)dp[Q]/100);
}
return 0;
}
补充:软件开发 , C++ ,