Topic Link: Click to open the link
Test instructions: Two people take turns from the n number each time select any number, each obtains the score is the selected number of the smallest, the two people to adopt the strategy is to make their score minus the other side of the score as large as possible, the final first person's scores.
Idea: Yesterday BC's C problem, because each time can choose a number of number, so ordinary greedy must not be. We can use D[i] to show that the number of I left when the initiator minus the maximum value of the following, so that each transfer is:
D[i] = max (a[j+1]-d[j]) (1 <= J <= i) means each transfer to a meaning: Select all the numbers j+1 to I, first sort, then this score is a[j+1].
See the code for details:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 1001001using namespace Std;int N,a[m];long long F[m],_max;int Main () { int T; scanf ("%d", &t); while (t--) { int i; scanf ("%d", &n); for (i=1;i<=n;i++) scanf ("%d", &a[i]); Sort (a+1,a+n+1); _MAX=A[1]; for (i=1;i<=n;i++) { F[i]=_max; _max=max (_max,a[i+1]-f[i]); } printf ("%i64d\n", F[n]); } return 0;}
HDU 5623 KK ' s number (DP)