hdu1864背包求找错

//我已经不能理解为什么WA了
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define MAXN 5000000

int Q;
int N;
int prices[35];
int m;
int n;
char type;
double price;
int F[MAXN];

int main()
{
    double q;
    while(cin>>q)
    {
        memset(F,0,sizeof(F));
        cin>>N;
        if(N == 0)
            break;
        Q = (int)(q*100);
        n = 0;
        for(int i = 1; i <= N; i++)
        {
            cin>>m;
            int sum = 0;
            int ma,mb,mc;
            ma = mb = mc = 0;
            char bd;
            bool flag = true;
            for(int j = 1; j <= m; j++)
            {
                cin>>type>>bd>>price;
                if(type!='A' && type!='B' && type!='C')
                {
                    flag = false;
                    break;
                }
                if(type == 'A')
                {
                    if(ma + price*100 <= 60000)
                        ma += price*100;
                    else
                    {
                        flag = false;
                        break;
                    }
                }
                if(type == 'B')
                {
                    if(mb + price*100 <= 60000)
                        mb += price*100;
                    else
                    {
                        flag = false;
                        break;
                    }
                }
                if(type == 'C')
                {
                    if(mc + price*100 <= 60000)
                        mc += price*100;
                    else
                    {
                        flag = false;
                        break;
                    }
                }
            }
            sum = ma + mb + mc;
            if(sum <= 100000 && flag == true)
            {
                n++;
                prices[n] = sum;
            } 
        }
        for(int i = 1; i <= n; i++)
        {
            for(int j = Q; j >= prices[i]; j--)
            {
                F[j] = max(F[j],F[j-prices[i]]+prices[i]);
            }
        }
        double ans =(double)(F[Q])/100.00;
        printf("%.2lf\n",ans);
    }
    return 0;
}

你可能感兴趣的:(hdu1864背包求找错)