HDU 1712 ACboy needs your help

该题是一道分组背包题;

题意就是ACboy发最多M的时间能够得到最多效益;输入有N没课程,没门课程发费j天得到的效益是map[i][j];

View Code
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int map[124][124];
inline int Max( int a , int b )
{
return a > b ? a : b;
}
int DP( int N , int M )
{
int f[124][124] ={ 0 };
for( int i = 1 ; i <= N ; i ++ )
{
for( int j = 1 ; j <= M ; j++ )
for( int k = M ; k >= j ; k-- )
{
f[i][k] = Max( f[i][k] ,f[i-1][k] );
f[i][k] = Max( f[i][k] , f[i-1][k-j] + map[i][j] );
}
}
return f[N][M];
}
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" ,&map[i][j] );
printf( "%d\n", DP( N ,M ) );
}
return 0;
}

 

你可能感兴趣的:(help)