I am speechless... Or the status is inaccurate ..
The transition equation of the initial state is very important, but it is not enough to simply introduce the equation.
Processing the boundary state and processing the Special State are all important. If a boundary state is wrong, it will lead to wa ....
Details! Clearer thinking and more comprehensive consideration!
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int N, T; int V [55]; int d [55] [10000]; int path [55] [10000]; int main () {int tt; scanf ("% d", & TT); For (INT Kase = 1; Kase <= tt; kase ++) {scanf ("% d", & N, & T); memset (path, 0, sizeof (PATH); memset (D, 0, sizeof (d); memset (v, 0, sizeof (v); For (INT I = 1; I <= N; I ++) {scanf ("% d", & V [I]) ;}for (INT I = N; I> = 1; I --) {for (Int J = 0; j <= T; j ++) {d [I] [J] = (I = N)? 0: d [I + 1] [J]; path [I] [J] = path [I + 1] [J]; If (j> = V [I]) {If (d [I] [J] <D [I + 1] [J-V [I] + 1) {path [I] [J] = V [I] + path [I + 1] [J-V [I]; d [I] [J] = d [I + 1] [J-V [I] + 1 ;} else if (d [I] [J] = d [I + 1] [J-V [I] + 1) path [I] [J] = max (path [I + 1] [J-V [I] + V [I], path [I + 1] [J]) ;}} int Max _ =-1; for (INT I = T-1; I> = 0; I --) {If (d [1] [I] = d [1] [T-1]) {If (max _ <path [1] [I]) max _ = path [1] [I];} printf ("case % d: % d \ n", Kase, d [1] [T-1] + 1, max _ + 678);} return 0 ;}