Maximum reimbursement amount of HDOJ1864

Source: Internet
Author: User

Maximum reimbursement Time Limit: 1000/1000 ms (Java/Other) Memory Limit: 32768/32768 K (Java/Other) Total Submission (s): 14 Accepted Submission (s ): 2 Problem Description a certain amount of invoices can be reimbursed for the current funds. The types of invoices that can be reimbursed include books (Class A), stationery (Class B), and travel (Class C). The total amount of each invoice must not exceed 1000 RMB, the value of a single item cannot exceed 600 RMB. Please write a program to find out the maximum reimbursement amount that can be reimbursed and does not exceed the given quota in a pile of invoices. The Input test Input contains several test cases. The first row of each test case contains two positive Q and N, where Q is the specified reimbursement quota and N (<= 30) is the invoice count. Followed by N rows of input, the format of each line is: m Type_1: price_1 Type_2: price_2... type_m: price_m where the positive integer m is the number of items opened on this invoice, Type_ I and price_ I are the types and values of items I. The item type is represented by an uppercase letter. When N is 0, all input ends, and the corresponding results are not output. Output outputs one line for each test case, that is, the maximum amount that can be reimbursed, accurate to 2 digits after the decimal point. Sample Input200.00 32 A: 23.50 B: 100.001 C: 650.003 A: 59.99 A: 120.00 X: 10.000000.00 22 B: 600.00 A: 400.001 C: 200.502.16.50 32 B: 600.00 A: 400.001 C: 200.501 A: 100.00100.00 0 Sample output123.501000.000000.50 question: first, give the maximum reimbursement amount and the number of invoices. Then, there are n invoices. Each invoice first gives the number of items on the invoice, then, the price of each item and item is given. Note: 1. only items a, B, and c can be reimbursed. invoices containing other items are voided. the value of a single item cannot exceed 600 3. the total value of each invoice cannot exceed 1000. The biggest value is output. It is also a question of 01 backpack. It is not difficult to write the code after knowing the conditions: the following code is wrong and cannot pass, I don't know why.

#include<iostream>   #include<stdio.h>   #include<cstring>   using namespace std;  int dp[3100000];  int w[1000];  int get_max(int a,int b){      return a>b?a:b;  }  int main(){      double Q;      int N,m,count,i,j,sum,a;      bool use;      while(scanf("%lf%d",&Q,&N)&&N){          count=0;          memset(dp,0,sizeof(dp));          for(i=0;i<N;i++){              scanf("%d",&a);              use=true;              sum=0;              for(j=0;j<a;j++){                  char type,temp1,temp2;                  double price;                  temp1=getchar();type=getchar();temp2=getchar();                  cin>>price;                  sum+=price*100;                  if(type<'A'||type>'C'||price>600||sum>100000)                      use=false;              }              if(use)                  w[count++]=sum;          }          int t=Q*100;          for(i=0;i<count;i++)             for(j=t;j>=w[i];j--)                  dp[j]=get_max(dp[j],dp[j-w[i]]+w[i]);          double ans=(double)dp[t]/100;          printf("%.2lf\n",ans);      }      return 0;  }  #include<iostream>#include<stdio.h>#include<cstring>using namespace std;int dp[3100000];int w[1000];int get_max(int a,int b){    return a>b?a:b;}int main(){    double Q;    int N,m,count,i,j,sum,a;    bool use;    while(scanf("%lf%d",&Q,&N)&&N){        count=0;        memset(dp,0,sizeof(dp));        for(i=0;i<N;i++){            scanf("%d",&a);            use=true;            sum=0;            for(j=0;j<a;j++){                char type,temp1,temp2;                double price;                temp1=getchar();type=getchar();temp2=getchar();                cin>>price;                sum+=price*100;                if(type<'A'||type>'C'||price>600||sum>100000)                    use=false;            }            if(use)                w[count++]=sum;        }        int t=Q*100;        for(i=0;i<count;i++)           for(j=t;j>=w[i];j--)                dp[j]=get_max(dp[j],dp[j-w[i]]+w[i]);        double ans=(double)dp[t]/100;        printf("%.2lf\n",ans);    }    return 0;}

 

I found the cause on the Internet and found that I had to reimburse the invoices separately. I don't know why. Can I reimburse the invoices separately... It means that only one part of the invoice is reimbursed... Let me know the code:
#include<stdio.h>   #include<string.h>     int N,i,j,t,num,k,q;  double Q,s;  char ch[20];  int f[3100000],w[1000],temp[31],sum,m[3];    int main()  {      while(scanf("%lf %d",&Q,&N)==2)      {          if(N==0)              break;          t=0;          q=(int)(Q*100);          memset(f,0,sizeof(f));          while(N--)          {              scanf("%d",&k);              memset(temp,0,sizeof(temp));              memset(m,0,sizeof(m));              for(i=0;i<k;i++)              {                  memset(ch,'\0',sizeof(ch));                  getchar();                  scanf("%s",ch);                  num=strlen(ch);                  for(j=2;j<num;j++)                  {                      if(ch[j]=='.')                          continue;                      temp[i]=10*temp[i]+(ch[j]-'0');                  }                  if(ch[0]=='A')                      m[0]+=temp[i];                  if(ch[0]=='B')                      m[1]+=temp[i];                  if(ch[0]=='C')                      m[2]+=temp[i];              }              if(ch[0]>='A' && ch[0]<='C' && m[0]<=60000 && m[1]<=60000 && m[2]<=60000 && (m[0]+m[1]+m[2])<=100000)              {                  for(i=0;i<k;i++)                  {                      w[t++]=temp[i];                      printf("w[%d]=%d\n",t-1,w[t-1]);                  }              }          }          for(i=0;i<t;i++)          {              for(j=q;j>=w[i];j--)                  f[j]=(f[j] > f[j-w[i]]+w[i] ? f[j] : f[j-w[i]]+w[i]);          }          s=(double)f[q]/100;          printf("%.2lf\n",s);      }      return 0;  }  #include<stdio.h>#include<string.h>int N,i,j,t,num,k,q;double Q,s;char ch[20];int f[3100000],w[1000],temp[31],sum,m[3];int main(){    while(scanf("%lf %d",&Q,&N)==2)    {        if(N==0)            break;        t=0;        q=(int)(Q*100);        memset(f,0,sizeof(f));        while(N--)        {            scanf("%d",&k);            memset(temp,0,sizeof(temp));            memset(m,0,sizeof(m));            for(i=0;i<k;i++)            {                memset(ch,'\0',sizeof(ch));                getchar();                scanf("%s",ch);                num=strlen(ch);                for(j=2;j<num;j++)                {                    if(ch[j]=='.')                        continue;                    temp[i]=10*temp[i]+(ch[j]-'0');                }                if(ch[0]=='A')                    m[0]+=temp[i];                if(ch[0]=='B')                    m[1]+=temp[i];                if(ch[0]=='C')                    m[2]+=temp[i];            }            if(ch[0]>='A' && ch[0]<='C' && m[0]<=60000 && m[1]<=60000 && m[2]<=60000 && (m[0]+m[1]+m[2])<=100000)            {                for(i=0;i<k;i++)                {                    w[t++]=temp[i];                    printf("w[%d]=%d\n",t-1,w[t-1]);                }            }        }        for(i=0;i<t;i++)        {            for(j=q;j>=w[i];j--)                f[j]=(f[j] > f[j-w[i]]+w[i] ? f[j] : f[j-w[i]]+w[i]);        }        s=(double)f[q]/100;        printf("%.2lf\n",s);    }    return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.