# Packet Backpack--hdu1712__ Backpack

Source: Internet
Author: User

 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.a.qHand in HandOnline acmersForum | DiscussStatistical charts Problem ArchiveRealtime Judge StatusAuthors ranklist C/c++/java ExamsACM StepsGo to JobContest LivecastIcpc@china STD ContestsVIP ContestsVirtual ContestsDIY | Web-diy BetaRecent contests LeeMail 0 (0)Control PanelSign out
Acboy needs your Help Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3038 accepted Submission (s): 1577

Problem Description Acboy has N courses this term, and him plans to spend in most M days on study. Of course,the profit he would gain from different course to on the "the" and "depending on it." How to arrange the "M" for the "N courses to maximize" profit?

Input the input consists of multiple data sets. A data set starts with a line containing two positive integers n and M, n are the number of courses, M is the the days Acboy ha S.
Next follow a matrix a[i][j], (1<=i<=n<=100,1<=j<=m<=100). A[I][J] Indicates if Acboy spend J days in 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 line which 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

packet backpack, each course looks for a group, and spends days as a fee

according to

For all Groups K
For V=v.. 0
For all I belong to Group K
F[v]=max{f[v],f[v-c[i]]+w[i]}

The code is as follows:

```#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int a[110][110];
int dp[110];
int main ()
{
//freopen ("In.txt", "R", stdin);
int n,m;
while (cin>>n>>m,n| | m)
{for
(int i=1; i<=n; i++) for
(int j=1; j<=m; j + +)
cin>>a[i][j];
Memset (Dp,0,sizeof (DP));
for (int i=1; i<=n; i++) for (int
j=m; j>0; j--) for
(int k=1; k<=m; k++)
if (j-k>=0)
Dp[j] =max (Dp[j],dp[j-k]+a[i][k]);
cout<<dp[m]<<endl;
}
return 0;
}
```

Related Keywords:

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.