The painful experience of the second phase of the 12th Lanqiao Cup School Simulation Competition

The painful experience of the second phase of the 12th Lanqiao Cup School Simulation Competition

See the meaning of the question clearly! Don't take it for granted!

Wrong two fill in the blanks directly explode orz

Third question

Problem description
 How many sequences meet the following conditions:

  1. The length of the sequence is 5.
  2. Each number in the sequence is an integer between 1 and 10.
  3. The following number in the sequence is greater than or equal to the preceding number.

At that time, I thought of a string of length 5, a single character is 1~9, when you see "an integer between 1 and 10", the interval orz is forced to open and close

answer

Answer: 2002

#include<iostream>
using namespace std;
int main()
{
    
    
    int sum=0;
    for(int i=1;i<=10;++i)
        for(int j=i;j<=10;++j)
            for(int k=j;k<=10;++k)
                for(int p=k;p<=10;++p)
                    for(int t=p;t<=10;++t)
                        ++sum;
    cout<<sum<<endl;
    return 0;
}

Fourth question

Problem description
  An undirected graph contains 2020 edges. If there are no self-loops and double edges in the graph, how many nodes should it contain at least?
  This is a fill-in-the-blank question, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. If you fill in the extra content, you will not be able to score.

answer

Answer: 65

I was too nervous when doing the problem, thinking that multiple points could not form a ring. Let the node think of the complete graph at least, and the number of complete graph edges formed by the node is the most when there are no self-loops and double edges. The number of edges in a complete graph with n vertices is n*(n-1)/2. Substituting this problem to calculate that it contains at least 65 nodes, it can reach 2020 edges.

Tenth question

Problem description
  Xiaolan plays a game in a grid with n rows and m columns.
  At the beginning, Xiao Lan stood in the upper left corner of the grid, that is, the first row and the first column.
  Xiaolan can walk around on the grid. If he is currently in row r and column c, he cannot walk to the row with row number smaller than r, nor to the column with column number smaller than c. At the same time, the straight-line distance he walked in one step was no more than 3.
  For example, if Xiaolan is currently in row 3 and column 5, he can go to row 3, column 6, row 3, column 7, row 3, column 8, row 4, column 5, and 4 One of row 6th column, 4th row 7th column, 5th row 5th column, 5th row 6th column, 6th row and 5th column.
  Xiaolan will eventually go to the nth row and mth column.
  In the picture, some positions have rewards, which can be obtained by walking up, and some positions have penalties, and you will be punished when walking up. Reward and punishment are finally abstracted into a weight, the reward is positive and the punishment is negative.
  Xiaolan hopes that after walking from the first row and the first column to the nth row and the mth column, the total weight sum is the largest. What is the maximum?
Input format
  The first line of input contains two integers n, m, indicating the size of the picture.
  The next n rows, each with m integers, represent the weight of each point in the grid.
Output format
  outputs an integer, which represents the maximum weight sum.
Sample input

3 5
-4 -5 -10 -3 1
7 5 -9 3 -10
10 -2 6 -10 -4

Sample output

15

Data size and conventions
  For 30% of the evaluation cases, 1 <= n, m <= 10;
  for 50% of the evaluation cases, 1 <= n, m <= 20;
  for all evaluation cases, 1 <= n <= 100 , -10000 <= weight <= 10000.

Problem solution This
problem needs to initialize the dp array to infinitesimal, because the problem may have all negative values, and then initialize dp[1][1] to the value of the first row and first column, which is the starting point. A position can reach 9 positions, which means that a position can be transferred from 9 positions. The value of this position is the maximum value of each value of the position that can be transferred from.

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int dir[9][2]={
    
    {
    
    0,-1},{
    
    0,-2},{
    
    0,-3},{
    
    -1,0},{
    
    -1,-1},{
    
    -1,-2},{
    
    -2,0},{
    
    -2,-1},{
    
    -3,0}};
const int N=110;
int map[N][N],dp[N][N];

int main()
{
    
    
    int n,m;
    scanf("%d%d",&n,&m);
    memset(dp,-0x3f,sizeof dp);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            scanf("%d",&map[i][j]);
    dp[1][1]=map[1][1];
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            for(int k=0;k<9;++k)
            {
    
    
                int x=i+dir[k][0];
                int y=j+dir[k][1];
                if(x>=1&&x<=n&&y>=1&&y<=m)
                    dp[i][j]=max(dp[i][j],dp[x][y]+map[i][j]);
            }
    printf("%d\n",dp[n][m]);
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_47156379/article/details/113120744