hdu 1712 dp 分组背包
题意:ACboy有n门考试 m天复习 a[i][j]表示第i门考试花j天复习可以得到的效益 求ACboy能得到的最大效益
思路:背包容量为m的分组背包 裸题
AC代码:
#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #define ll long long #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a) memset(a,0,sizeof(a)) using namespace std; const int N=1e5+100; int main(){ int dp[105],a[105][105]; int n,m; while((cin>>n>>m)&&(m+n)){ mem(dp); for(int i=1; i<=n; ++i){ for(int j=1; j<=m; ++j){ cin>>a[i][j]; } } for(int i=1; i<=n; ++i){ for(int v=m; v>=1; --v){ for(int k=1; v-k>=0; ++k){ dp[v]=max(dp[v],dp[v-k]+a[i][k]); } } } cout<<dp[m]<<endl; } return 0; }