ACboy needs your help
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6242 Accepted Submission(s): 3427
Next follow a matrix A[i][j], (1<=i<=N<=100,1<=j<=M<=100).A[i][j] indicates if ACboy spend j days on ith course he will get profit of value A[i][j].
N = 0 and M = 0 ends the input.
<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=105;
int value[maxn][maxn];
int dp[maxn];
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m) && (n||m))
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++){
scanf("%d",&value[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<=j;k++)
{
if(dp[j]<dp[j-k]+value[i][k])
dp[j]=dp[j-k]+value[i][k];
}
}
}
printf("%d\n",dp[m]);
}
return 0;
}</span>