2019 summer cattle off training match (up questions and notes)

First round

 

E title: ABBA

Bobo has a length of 2 (n + m) of the string, by the character "A" and "B" components. The string also has attractive properties: it can be decomposed into (n + m) of length sub-sequence 2, and (n + m) th sequence, n is subsequences of them as "AB", and the other of m as "BA".

Q: Now given n and m, may I ask you, the maximum number of strings satisfying the above conditions can be found?

Understanding the problem: the title, decomposed into "sequences" rather than "substring"; that is, the length of subsequence 2 may be discontinuous. As BBABAA, the string has three 'BA'.

 

second round

 

H title: Second Large of the Rectangle (1 times Daquan matrix)

 Q: Given a binary matrix of N x M, the second output requested by the entire large area of ​​the rectangular configuration of a size.

A: calculating the position of each successive two-dimensional matrix of 1, monotonous stack. (Bu Ti: Ding Depot)

 1 #include<map>
 2 #include<cmath>
 3 #include<string>
 4 #include<cstdio>
 5 #include<cstring>
 6 #include<iostream>
 7 #include<algorithm>
 8 #define inf 0x3f3f3f3f
 9 using namespace std;
10 const int maxn = 1e3+5;
11 int sum[maxn][maxn],Stack[maxn],n,m;
12 int main()
13 {
14     string s;
15     while(~scanf("%d%d", &n, &m))
16     {
17         memset(sum,0,sizeof(m));
18         for(int i=1; i<=n; i++)
19         {
20             cin>>s;
21             for(int j=0; j<m; j++)
22             {
23                 if(s[j]=='0') sum[i][j+1]=0;
24                 else sum[i][j+1]=sum[i][j]+1;
25             }
26         }
27         int m1=0,m2=0;
28         Stack[0]=0;
29         for(int j=m; j>0; j--)
30         {
31             int top=0;
32             Stack[0]=0;
33             for(int i=1; i<=n; i++)
34             {
35                 if(sum[i][j]>=sum[Stack[top]][j])
36                     Stack[++top]=i;
37                 else
38                 {
39                     int len;
40                     while(sum[i][j]<sum[Stack[top]][j])
41                     {
42                         len=i-Stack[top-1]-1;
43                         int s=sum[Stack[top]][j]*len;
44                         if(s>m1)
45                         {
46                             m2=max(m1,sum[Stack[top]][j]*(len-1));
47                             m1=s;
48                         }
49                         else if(s==m1)
50                             m2=m1;
51                         else if(s>m2)
52                             m2=s;
53                         top--;
54                     }
55                     Stack[++top]=i;
56                 }
57             }
58             for(int i=1; i<=top; i++)
59             {
60                 int s=sum[Stack[i]][j]*(Stack[top]-Stack[i-1]);
61                 if(s>m1)
62                 {
63                     m2=max(m1,sum[Stack[i]][j]*(Stack[top]-Stack[i-1]-1));
64                     m1=s;
65                 }
66                 else if(s==m1)
67                     m2=m1;
68                 else if(s>m2)
69                     m2=s;
70             }
71         }
72         printf("%d\n",m2);
73     }
74     return 0;
75 }
View Code

 

F题:Partition problem

Q: give you 2 * N individuals, there is a competition between the value of every two people, the value of competition between the owners expressed out by the two-dimensional array. Now, will you let these people divided into two teams, each N-person, two teams compete; seek to produce the maximum value for how much competition?

Understanding the problem: 2 * N people divided into two teams, no competition between the teammates of the same value within the team; a member of a team, and the value will be calculated once the competition among each member of another team.

 

Guess you like

Origin www.cnblogs.com/Amaris-diana/p/11223337.html