This is a good question.
First, sort the life values of a soldier. Then we can know that a can only kill one person for each blood volume.
We began to get greedy for every amount of blood. How many steps should we take to attack this amount of blood.
DP [J]: We still have J remaining attacks, the number of small soldiers killed,
From 1 to the maximum volume of small soldiers.
# Include <iostream>
# Include <stdio. h>
# Include <vector>
# Include <queue>
# Include <stack>
# Include <string. h>
# Include <algorithm>
# Include <math. h>
Using namespace STD;
# Define ll long
# Define lcm (a, B) (a * B/gcd (a, B ))
// O (n) calculates the prime number, and 1-N is the Euler's number.
# Define n 1500001
Int A [1100];
Int B [1100];
Int C [1100];
Int DP [1100];
Int main ()
{
Int T;
Int CAS = 0;
Cin> T;
Int N;
While (t --)
{
CAS ++;
Scanf ("% d", & N );
Int m = 0;
For (INT I = 1; I <= N; I ++)
{
Scanf ("% d", & A [I]);
M = max (A [I], M );
}
Sort (a + 1, A + n + 1 );
Memset (C, 0, sizeof (c ));
For (INT I = 1; I <= N; I ++)
{
Int J = A [I];
While (C [J] & J> 0) j --;
If (J! = 0) B [J] = A [I]-J;
C [J] = 1;
}
Memset (DP, 0, sizeof (DP ));
Int Maxx =-1;
For (INT I = 1; I <= m; I ++)
{
For (Int J = I; j> = 1; j --) DP [J] = DP [J-1];
For (Int J = 0; j <= I; j ++)
{
If (j> B [I] & C [I]) DP [J-B [I]-1] = max (DP [J-B [I]-1], DP [J] + 1 );
}
}
For (Int J = 0; j <= m; j ++) Maxx = max (Maxx, DP [J]);
Printf ("case # % d: % d \ n", Cas, Maxx );
}
Return 0;
}
Hdu-4976-A simple greedy problem.