[State compression] [Dynamic Planning] e-Sports

Source: Internet
Author: User
[Problem description] every year at the Beijing informatics winter camp, students will carry out a variety of e-sports activities in their spare time. After years and years of practice, the students are already very familiar with each other's strengths, so that they have produced a set of competitive scoring systems. This system quantifies each person's strength into an integer. In addition, for the people a and B of RA and Rb respectively, this system quantifies the general results of their battles into a real score about their strength values:

Among them, EA and EB are the scores that a and B usually get in the battle. For example, if Ra = 2432, rB = 2611, the score obtained by a is

However, the winter camp this year is slightly different from the past. The students are divided into two teams with the same number of members to start a group competition. The bosses of each team arrange an order for their team members. Then, the first and second teams compete with each other in order, and so on. For each contestant in A group competition, we can calculate their respective combat scores based on their strength. The score of the two teams in this competition order is the score of each contestant in this order. For the sake of fair competition, the students agreed on an integer (l), and stipulated that the players in a team whose team is actually X must be placed before all players whose strength is strictly less than X-L. For example, if l = 100, a contestant with a strength of 2437 must be placed before the contestant with the team's strength of 2336, but not necessarily before the contestant with the team's strength of 2337. As the boss of a team, you have used various improper means to create a sequence of well-arranged team members. You also know the strength of your team and each other. Your current task is to find ways to arrange the order of team members so that your team has the highest score in the battle. [Input file] the first line of the input file contains an integer N, representing the number of people in each team. In the next n rows, each line has an integer, indicating the capacity of each member. In the next n rows, each line has an integer, indicating the competence of each member of the other team in turn. The last line contains an integer representing L. Output file: the output file contains only one real number, indicating the maximum score you may obtain. The answer is rounded to the six digits after the decimal point. [sample input] 422392412239922672534242923402389100 [sample output] 1.483574 [sample description] according to the rules in the question, there may be only four possible order, their scores are listed in the following order: 2399 2412 2239 2267 1.480409862399 2412 2267 2239 1.483573612412 2399 2239 2267 1.478153482412 2399 2267 2239 1.48131723 Note: If there is no limit on L, sort 2239 2267 2399 2412 to get more scores. However, since 2239 and 2267 do not allow 2399 and 2412 to appear before, this is impossible. [Data scale] for 100% of data, 1 ≤ n ≤ 20 is true. For 100% of the data, each person's capacity is between 1500 and 3000. For 100% of data, 0 ≤ L ≤ 1500 is true. For 100% of data, the capacity value of the I-th Member in the order in which your opponent's team is arranged is greater than or equal to the capacity value of any member after the I-th Member in the opponent's team.

Status compression dynamic planning.
Status: a collection of contestants who have already participated in the competition.
During the transfer, the current contestant is enumerated. If he has not participated in the competition and meets the given conditions in the question, the total score corresponding to the set to which the contestant joins is updated.

One optimization: sort the contestant's strength values (the sorting direction does not matter ), then, you only need to select a contestant with the minimum strength among all contestants who have already participated in the competition for determination (because if the contestant can meet the conditions, other players who are more powerful than him will certainly be able to meet the conditions ).
Accode:

# Include <cstdio> # include <cstdlib> # include <algorithm> # include <cmath> const int maxn = 30; const int maxstatus = 1 <20; double f [maxstatus], cost [maxn] [maxn]; // as the status changes, the number of people in the collection increases, // Therefore, the previous status does not affect the subsequent status, so that you can scroll locally. Int A [maxn], B [maxn], n, l, Pst, ths = 1; int CNT [2], status [2] [maxstatus]; // The CNT array is used to record the total number of all States that need to be enumerated currently. // It is stored in status to reduce the enumeration volume and prevent enumeration of invalid states. Inline bool check (int s, int I) {for (Int J = n-1, TMP = 1 <j; TMP> = 1, -- J) if (TMP & S) return a [I]-l <= A [J]; return 1 ;}int main () {freopen ("compete. in "," r ", stdin); freopen (" compete. out "," W ", stdout); scanf (" % d ", & N); For (INT I = 0; I <n; ++ I) scanf ("% d", A + I); For (INT I = 0; I <n; ++ I) scanf ("% d", B + I ); scanf ("% d", & L); For (INT I = 0; I <n; ++ I) for (Int J = I + 1; j <N; ++ J) if (a [I] <A [J]) STD: swap (A [I], a [J]); for (INT I = 0; I <n; ++ I) for (Int J = 0; j <n; ++ J) cost [I] [J] = (1.l/(1. + POW (10.l, (B [J]-A [I])/400.l)); // the score of the combat result can be preprocessed to avoid multiple computations. // Sort and then pre-process the score. Status [ths] [CNT [ths] ++] = 0; For (INT I = 0; I <n; ++ I) {STD: swap (PST, ths); CNT [ths] = 0; For (int K = 0; k <CNT [PST]; ++ K) {int last = status [PST] [k]; double val = f [last]; for (Int J = 0; j <n; ++ J) if (! (Last & (1 <j) if (check (last, j) {int now = last | (1 <j ); if (F [now] <1e-12) status [ths] [CNT [ths] ++] = now; if (Val + cost [J] [I]> F [now]) f [now] = Val + cost [J] [I];} else break ;}} printf ("%. 6lf ", F [(1 <n)-1]); Return 0 ;}

Paste a simple search program:

#include <cstdio>#include <cstdlib>#include <algorithm>#include <cmath>const char fi[] = "compete.in";const char fo[] = "compete.out";const int maxN = 30;int a[maxN], b[maxN], c[maxN];bool tag[maxN];int n, L;double ans = 0, cost[maxN][maxN];void init_file(){    freopen(fi, "r", stdin);    freopen(fo, "w", stdout);    return;}inline bool cmp(const int &a, const int &b){return a > b;}void readdata(){    scanf("%d", &n);    for (int i = 0; i < n; ++i)        scanf("%d", a + i);    for (int i = 0; i < n; ++i)        scanf("%d", b + i);    scanf("%d", &L);    std::sort(a, a + n, cmp);    for (int i = 0; i < n; ++i)    for (int j = 0; j < n; ++j)        cost[i][j] = (1.L / (1. + pow(10.L,            (b[j] - a[i]) / 400.L)));    return;}void print(){    double tmp = 0;    for (int i = 0; i < n; ++i)        tmp += cost[c[i]][i];    if (tmp > ans) ans = tmp;    return;}void Dfs(int i){    if (i >= n) {print(); return;}    for (int j = 0; j < n; ++j)    {        if (tag[j]) continue;        if (a[j] - L > a[c[i - 1]]) break;        c[i] = j; tag[j] = 1;        Dfs(i + 1); tag[j] = 0;    }    return;}void work(){    for (int i = 0; i < n; ++i)    if (a[0] - a[i] <= L)    {        c[0] = i;        tag[i] = 1;        Dfs(1);        tag[i] = 0;    }    printf("%.6lf\n", ans);    return;}int main(){    init_file();    readdata();    work();    return 0;}

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.