HDU 5623 KK ' s number (DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.