NOIP2010PJ Three Kingdoms game [game theory]

Source: Internet
Author: User

Title Description

Xiao Han is fond of computer games, these days he is playing a game called "Three Kingdoms".

In the game, the small culvert and the computer each party, the formation of their respective armies to battle. There is a total of N-Generals in the game (n is even and not less than 4), and any two generals have a "tacit value", indicating how powerful the combination would be if the two generals fought as a pair. Before the game began, all the generals were free (called the Free Generals, once a free warlord was chosen as a member of a certain army, then he was no longer a free warlord), in other words, the so-called free generals do not belong to either party.

The game begins, the small culvert and the computer to choose from a free warlord to form their own army, the rules are as follows: Xiao Han first elected a free military commander to join his own army, and then the computer from the free generals elected a computer to join the army. Followed by the "small culvert → computer → small Culvert → ..." in the order of the selection of the generals, until all the generals were evenly divided between the two sides. Then, the program automatically picks a pair from each of the two armies with the highest tacit value.

The generals ' combination represented their own armies in a two-to-two tournament, with a higher tacit value of a pair of generals winning, indicating that the two armies were at war, with the winner of the winning warlord combination.

It is known that the principle of choosing a warlord is to try to undermine the strongest combination that the opponent will form next, and it takes the following specific strategies: any time, when it is time to pick up the computer, it will attempt to match each of the generals in the opponent's army with one by one of each of the current free generals, to find out the combination of the strongest pairs And elect the free generals in the group into their own armies. The following is an example of a computer's selection strategy, for example, a total of 6 generals in the game, and the tacit values between them are shown in the following table:

The two sides select the process as follows:

Xiao Han want to know, if the computer in a game always adhere to the above strategy, then there is no possibility that they will

Wins? If so, in all possible victories, the tacit value of the combination of the generals used in the tournament is much greater.

Less? Assume that during the entire game, both sides can see the generals of the free generals and the generals of the opposing armies at any time. In order to simplify the problem, it is ensured that the tacit value of the different generals ' combinations is not the same.

Input/output format

Input format:

The input file name is sanguo.in, a total of N rows.

The first behavior is an even N, which represents the number of generals.

Line 2nd to line N, line (i+1) has (Ni) a non-negative integer, with a space between every two numbers

To indicate the tacit value between the commander I and the I+1,i+2,......,n (0≤ tacit value ≤1,000,000,000).

Output format:

Output file Sanguo.out A total of 1 or 2 rows.

For a given game input, there is a selection sequence that allows the small culvert to win, then output 1, and another line of output

In all the winning cases, the maximum tacit value of the final selection of the warlord combination is the small culvert.

If there is no choice to let the small culvert win the order, then output 0.

Input and Output Sample input example # #:
Sample # # of output:
"Output Sample 1" 132 "output Example 2" 177
Description

"Data Range"

There is n≤10 for 40% of the data.

There is n≤18 for 70% of the data.

There is n≤500 for 100% of the data.

For any one of the generals I, assuming that its tacit understanding of the highest of J, followed by K, then the small culvert to get (I,J) is impossible, to get (i,k) really 100%; Similarly, computers want to get (I,J) and (i,k) is impossible.

Maximum value per row

Be sure to analyze it later

#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;Const intn=505; inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN,m,ans,a[n][n];intMain () {n=read ();  for(intI=1; i<=n;i++)         for(intj=i+1; j<=n;j++) a[i][j]=a[j][i]=read ();  for(intI=1; i<=n;i++){        intt1=0, t2=0;  for(intj=1; j<=n;j++){            if(A[I][J]&GT;T1) t2=t1,t1=A[i][j]; Else if(A[I][J]&GT;T2) t2=A[i][j]; } ans=Max (ANS,T2); } printf ("1\n%d", ans);}

NOIP2010PJ Three Kingdoms game [game theory]

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.