hdu 1712 ACboy needs your help(分组背包)

分组背包一水~

View Code
 1 /*

 2 Author:Zhaofa Fang

 3 Lang:C++

 4 */

 5 #include <cstdio>

 6 #include <cstdlib>

 7 #include <sstream>

 8 #include <iostream>

 9 #include <cmath>

10 #include <cstring>

11 #include <algorithm>

12 #include <string>

13 #include <utility>

14 #include <vector>

15 #include <queue>

16 #include <stack>

17 #include <map>

18 #include <set>

19 using namespace std;

20 

21 typedef long long ll;

22 #define DEBUG(x) cout<< #x << ':' << x << endl

23 #define REP(i,n) for(int i=0;i < (n);i++)

24 #define FOR(i,s,t) for(int i = (s);i <= (t);i++)

25 #define FORD(i,s,t) for(int i = (s);i >= (t);i--)

26 #define PII pair<int,int>

27 #define PB push_back

28 #define MP make_pair

29 #define ft first

30 #define sd second

31 #define lowbit(x) (x&(-x))

32 #define INF (1<<30)

33 

34 int A[105][105],f[105];

35 int main()

36 {

37     //freopen("in","r",stdin);

38     //freopen("out","w",stdout);

39     int n,m;

40     while(~scanf("%d%d",&n,&m))

41     {

42         if(!n&&!m)break;

43         FOR(i,1,n)FOR(j,1,m)scanf("%d",&A[i][j]);

44         memset(f,0,sizeof(f));

45 

46         FOR(k,1,n) FORD(v,m,0) FOR(i,1,m)

47         if(v>=i)f[v] = max(f[v],f[v-i]+A[k][i]);

48 

49         printf("%d\n",f[m]);

50     }

51     return 0;

52 }

 

你可能感兴趣的:(help)