Description
A tournament can be represented by a complete graph in which each vertex denotes a player and a directed edge is from vertex x to vertex y if player x beats player y. For a player x in a tournament T, the score of x is the number of players beaten by x. The score sequence of T, denoted by S(T) = (s1, s2, . . . , sn), is a non-decreasing list of the scores of all the players in T. It can be proved that S(T) = (s1, s2, . . . , sn) is a score sequence of T if and only if
for k = 1, 2, . . . , n and equality holds when k = n. A player x in a tournament is a strong king if and only if x beats all of the players whose scores are greater than the score of x. For a score sequence S, we say that a tournament T realizes S if S(T) = S. In particular, T is a heavy tournament realizing S if T has the maximum number of strong kings among all tournaments realizing S. For example, see T2 in Figure 1. Player a is a strong king since the score of player a is the largest score in the tournament. Player b is also a strong king since player b beats player a who is the only player having a score larger than player b. However, players c, d and e are not strong kings since they do not beat all of the players having larger scores. The purpose of this problem is to find the maximum number of strong kings in a heavy tournament after a score sequence is given. For example,Figure 1 depicts two possible tournaments on five players with the same score sequence (1, 2, 2, 2, 3). We can see that there are at most two strong kings in any tournament with the score sequence (1, 2, 2, 2, 3) since the player with score 3 can be beaten by only one other player. We can also see that T2 contains two strong kings a and b. Thus, T2 is one of heavy tournaments. However, T1 is not a heavy tournament since there is only one strong king in T1. Therefore, the answer of this example is 2.
Input
The first line of the input file contains an integer m, m <= 10, which represents the number of test cases. The following m lines contain m score sequences in which each line contains a score sequence. Note that each score sequence contains at most ten scores.
Output
The maximum number of strong kings for each test case line by line.
Sample Input
51 2 2 2 31 1 3 4 4 4 43 3 4 4 4 4 5 6 6 60 3 4 4 4 5 5 5 60 3 3 3 3 3
Sample Output
24535
【分析】
主要是有一个贪心的思想,就是如果有一种情况使其中k个人是能力者的话,那么总有一种情况使分数最高的k个人是能力者。(因为交换一下胜利的场就可以了)。所以可以枚举有k个人是能力者,规定后k个人就是能力者,建立约束图,跑最大流判满流即可。
如下图(证明上面那一个贪心):
假设有一种情况使得有k个能力者,但不是后k个,证明有一种情况是后k个都是能力者。
上图,假设C是能力者但不是后k个,E不是能力者但是后k个。
因为C是能力者E不是,则在E的后面必有一个G(随便是什么),C赢了它,E没有赢他。
因为E的分数大于C,则在C之前必有一个A(随便是什么),C没有赢他,E赢了他。
那么我们交换一下胜负场,C、E分数都不变,然后E离能力者更近一步。
继续交换下去,后k个一定能成为能力者。
证毕。
于是建个图跑最大流。
差不多这样建图:
代码如下:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define Maxn 1100 9 #define Maxm 100100 10 #define INF 0xfffffff 11 12 char s[1010]; 13 int a[Maxn],al,lg[Maxn]; 14 int dis[Maxn],first[Maxn]; 15 16 struct node 17 { 18 int x,y,f,o,next; 19 }t[Maxm];int len; 20 21 int st,ed,sum,h=0; 22 23 int mymin(int x,int y) { return x