分组背包入门题

http://acm.hdu.edu.cn/showproblem.php?pid=1712

#include<bits/stdc++.h>
using namespace std;
int a[105][105];
int f[105];
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)&&m&&n)
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                scanf("%d",&a[i][j]);
        memset(f,0,sizeof(f));
        for(int i=1;i<=n;i++)
            for(int j=m;j>=0;j--)
                for(int k=1;k<=j;k++)
                {
                    f[j]=max(f[j],f[j-k]+a[i][k]);
                }
        printf("%d
",f[m]);
    }
}
原文地址:https://www.cnblogs.com/dongdong25800/p/11020733.html