|
Online Judge |
Online Exercise |
Online Teaching |
Online Contests |
Exercise Author |
F.a.q Hand in Hand Online acmers Forum | Discuss Statistical charts |
Problem Archive Realtime Judge Status Authors ranklist
|
C/c++/java Exams ACM Steps Go to Job Contest Livecast Icpc@china
|
STD Contests VIP Contests Virtual Contests DIY | Web-diy Beta Recent contests |
Lee Mail 0 (0) Control Panel Sign 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;
}