Idea: 3D ~~~~~
AC code:
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <cstring>
# Include <algorithm>
Using namespace std;
Const int Max = 100 + 10;
Const int base = 2;
Const int inf =-0x7fffffff;
Int dp [Max] [Max] [10];
Struct Monster
{
Int;
Int B;
Int w;
} G [Max];
Int dp_find (int n, int v1, int v2, int k)
{
Int x, y, I, j;
Memset (dp, 0, sizeof (dp ));
For (x = 0; x <n; x ++)
{
For (y = v1; y> = 0; y --)
{
For (I = v2; I> = 0; I --)
{
For (j = k; j> = 0; j --)
{
Int temp = dp [y] [I] [j];
If (y> = g [x].)
Temp = max (temp, dp [y-g [x]. a] [I] [j] + g [x]. w );
If (I> = g [x]. B)
Temp = max (temp, dp [y] [I-g [x]. B] [j] + g [x]. w );
If (j> = 1)
Temp = max (temp, dp [y] [I] [J-1] + g [x]. w );
Dp [y] [I] [j] = max (dp [y] [I] [j], temp );
}
}
}
}
Return dp [v1] [v2] [k];
}
Int main ()
{
Int I, j, n, m, k, v1, v2;
While (~ Scanf ("% d", & n, & v1, & v2, & k ))
{
For (I = 0; I <n; I ++)
Scanf ("% d", & g [I]. a, & g [I]. B, & g [I]. w );
// Puts ("find is ging \ n ");
Printf ("% d \ n", dp_find (n, v1, v2, k ));
}
}
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <cstring>
# Include <algorithm>
Using namespace std;
Const int Max = 100 + 10;
Const int base = 2;
Const int inf =-0x7fffffff;
Int dp [Max] [Max] [10];
Struct Monster
{
Int;
Int B;
Int w;
} G [Max];
Int dp_find (int n, int v1, int v2, int k)
{
Int x, y, I, j;
Memset (dp, 0, sizeof (dp ));
For (x = 0; x <n; x ++)
{
For (y = v1; y> = 0; y --)
{
For (I = v2; I> = 0; I --)
{
For (j = k; j> = 0; j --)
{
Int temp = dp [y] [I] [j];
If (y> = g [x].)
Temp = max (temp, dp [y-g [x]. a] [I] [j] + g [x]. w );
If (I> = g [x]. B)
Temp = max (temp, dp [y] [I-g [x]. B] [j] + g [x]. w );
If (j> = 1)
Temp = max (temp, dp [y] [I] [J-1] + g [x]. w );
Dp [y] [I] [j] = max (dp [y] [I] [j], temp );
}
}
}
}
Return dp [v1] [v2] [k];
}
Int main ()
{
Int I, j, n, m, k, v1, v2;
While (~ Scanf ("% d", & n, & v1, & v2, & k ))
{
For (I = 0; I <n; I ++)
Scanf ("% d", & g [I]. a, & g [I]. B, & g [I]. w );
// Puts ("find is ging \ n ");
Printf ("% d \ n", dp_find (n, v1, v2, k ));
}
}