I don't know where I wrote the wrong backpack for the Fuzhou University April semi-finals 01. Please give me some advice.

Source: Internet
Author: User
// Question link http://acm.fzu.edu.cn/contest/problem.php? Cid = 126 & sortid = 4
#include<stdio.h>#include<string.h>struct node{  int x;  int y;       }a[110];int dp[110][1100];int max(int x,int y){  if(x>y)  return x;  return y;   }int min(int x,int y){  if(x<y)  return x;  return y;    }int main(){    int n,m,i,sum,j,aa,bb,k;     while(scanf("%d%d",&n,&m)!=EOF)     {       sum=0;       memset(dp,0,sizeof(dp));              for(i=1;i<=n;i++)       {         scanf("%d%d",&a[i].x,&a[i].y);         sum=sum+a[i].x;       }       scanf("%d%d",&aa,&bb);              for(i=1;i<=n;i++)       {          //for(k=min(i,m);k>=1;k--)                for(k=1;k<=min(i,m);k++)                    for(j=sum;j>=a[i].x;j--)           {            dp[k][j]=max(dp[k-1][j],dp[k-1][j-a[i].x]+a[i].y);                                             }       }       /*         printf("%d************\n",sum);         for(i=0;i<=n;i++)         {          for(j=0;j<=sum;j++)           printf("(%d,%d)%d ",i,j,dp[i][j]);           printf("\n");         }         */       int max=-1;                          for(i=aa;i<=sum;i++)       {          if(dp[m][i]>=bb)          {             if((i+dp[m][i]-aa-bb)>max)               max=(i+dp[m][i]-aa-bb);               // printf("(%d,%d)%d ",m,i,dp[m][i]);                 }          printf("\n");       }             //if(max==-1)        printf("%d\n",max);     }         return 0;    }/*3 2 1 10 3 2 3 4 5 3*/

Problem D buy candy Accept: 35 Submit: 127 Time Limit: 1000 mSec Memory Limit: 32768 KBProblem Description Qing Mingjun, 51 Jun and 61 Jun three people are good friends. They like to go to a candy store to buy candy, which is sold in two flavors: Chocolate and strawberry. Qing Mingjun prefers chocolate-flavored candy. 61 Jun prefers strawberry-flavored candy. 51 Jun is a fool, and he prefers both flavors. The store owner mixed two flavors of candy in a jar, so the quantity of each candy in each jar may be different. On this day, Qing Mingjun, May 1jun, and 61 Jun went to buy candy. Their money can only buy m cans of candy. Qing Mingjun wants a chocolate-flavored candy. 61 Jun wants B strawberry-flavored candy, and 51 Jun wants more candy, the better. May 1jun wants to know how many sweets he can eat at most to meet the requirements of Qing Ming Jun and 61 Jun. The Input contains multiple groups of data. For each group of data, the first behavior is two integers n, m (1 <= m <= n <= 100 ), it indicates the total number of candy cans in the candy store and the number of cans they can buy. Next there are n rows, each row has two integers x, y (0 <= x, y <= 10 ), x chocolate-flavored candy and y strawberry-flavored candy are in the I-Can candy. The last row contains two integers, a and B. It indicates that Qing Mingjun wants a chocolate-flavored candy, and 61 Jun wants B strawberry-flavored candy. Output each group of test data outputs an integer in one row, which is the maximum number of Sweets that can be eaten by May 1st. If there is no solution that meets the requirements of Qingming June and liujun,-1 is output. Sample Input3 2 1 10 3 3 4 5 3 Sample Output4dp [I] [j] indicates the number of sugar y in the first I items.

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.