Hdu1712acboy needs your help "group backpack"

Source: Internet
Author: User

Acboy needs your help

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6249 Accepted Submission (s): 3430


Problem Description

Acboy has N courses the term, and he plans to spend atmost M days on study. Of course,the profit he would gain from different coursedepending on the days he spend on it. How to arrange the M days for the ncourses to maximize the profit?

Input

The input consists of multiple data sets. A data setstarts with a line containing-positive integers n and M, n is the number ofcourses, and M is the th acboy has.
Next follow a matrix a[i][j], (1<=i<=n<=100,1<=j<=m<=100). A[I][J] indicates if acboy spendj days on ith course he'll get profit of value a[i][j].
N = 0 and M = 0 ends the input.

Output

For each data set, your program should output a Linewhich contains the number of the max profit Acboy would gain.

Sample Input

2 2

1 2

1 3

2 2

2 1

2 1

2 3

3 2 1

3 2 1

0 0

Sample Output

3

4

6

Test instructions

Give you a n*m matrix, line represents the I-course, column represents the length of time to take this course, the matrix value represents the benefits obtained, the output maximum benefit.

Input:

The number of input n rows m column after input n,m represents the benefit

Bare packet knapsack problem .....

#include <iostream>#include<cstring>using namespacestd;intn,m;inta[111][111];intf[111];intMain () { while(cin>>n>>m) {if(n==0&&m==0)             Break;  for(intI=1; i<=n;i++)             for(intj=1; j<=m;j++) Cin>>A[i][j]; Memset (F,0,sizeof(f));  for(intI=1; i<=n;i++)             for(intj=m;j>=0; j--)                 for(intk=1; k<=j;k++) F[j]=max (f[j],f[j-k]+A[i][k]); cout<<f[m]<<Endl; }    return 0;}
View Code

Hdu1712acboy needs your help "group backpack"

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.