这道题我就想说一点:审题!附件只有2个!钱是10的整数倍,不是100的整数倍!
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAX_OBJ = 60, MAX_V = 5000, MINF = 0xcfcfcfcf; int ObjCnt[MAX_OBJ], V[MAX_OBJ][5], W[MAX_OBJ][5]; int F[MAX_V]; int TotV, TotObj; int Dp() { memset(F, MINF, sizeof(F)); F[0] = 0; for (int i = 1; i <= TotObj; i++) for (int j = TotV; j >= 0; j--) for (int k = 1; k <= ObjCnt[i]; k++) if (V[i][k] <= j) F[j] = max(F[j], F[j - V[i][k]] + W[i][k]); int ans = 0; for (int j = 1; j <= TotV; j++) ans = max(ans, F[j]); return ans; } int main() { scanf("%d%d", &TotV, &TotObj); for (int i = 1; i <= TotObj; i++) ObjCnt[i] = 1; TotV /= 10; for (int i = 1; i <= TotObj; i++) { int v, w, group; scanf("%d%d%d", &v, &w, &group); v /= 10; if (group == 0) { V[i][1] = v; W[i][1] = w * v; } else { ObjCnt[group]++; V[group][ObjCnt[group]] = v; W[group][ObjCnt[group]] = w * v; } } for (int i = 1; i <= TotObj; i++) { if (ObjCnt[i] == 1 && !V[i][1]) ObjCnt[i] = 0; else if (ObjCnt[i] == 2) { V[i][2] += V[i][1]; W[i][2] += W[i][1]; } else if (ObjCnt[i] == 3) { ObjCnt[i]++; V[i][4] = V[i][1] + V[i][2] + V[i][3]; W[i][4] = W[i][1] + W[i][2] + W[i][3]; V[i][2] += V[i][1]; W[i][2] += W[i][1]; V[i][3] += V[i][1]; W[i][3] += W[i][1]; } } printf("%d ", Dp() * 10); return 0; }