For each course, the learning time is different, the harvest is different, in a course spent two different time to learn is mutually exclusive, that is, they belong to the same group of items, directly do group backpack can.
Be aware that the order of the triple loops is immutable!
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 6 Const intINF =-99999999;7 Const intN =101;8 intA[n][n];9 intDp[n];Ten intN, M; One A intMain () - { - while(SCANF ("%d%d", &n, &m)! =EOF) the { - if(n = =0&& m = =0) Break; - for(inti =1; I <= N; i++ ) - { + for(intj =1; J <= M; J + + ) - { +scanf"%d", &a[i][j]); A } at } -Memset (DP,0,sizeof(DP)); - for(inti =1; I <= N; i++ ) - { - for(intj = m; J >0; j-- ) - { in for(intK =1; K <= J; k++ ) - { toDP[J] = max (Dp[j], dp[j-k] +a[i][k]); + } - } the } *printf"%d\n", Dp[m]); $ }Panax Notoginseng return 0; -}
Note: There is no requirement to use enough m days, that is, the backpack can be dissatisfied.
HDU 1712 Group Backpack Starter