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"