[daily question 1] preparing for the Blue Bridge Cup -- Python programming | Day06 | decorative beads | real question code analysis

πŸ’– About the author: Hello, I'm brother cheshen, cheshen at No. 18 Fuxue road πŸ₯‡
⚑ About - > Che Shen: the fastest time from the bedroom to the laboratory is 3 minutes, and the slowest time is 3.5 minutes (that half minute is actually waiting for the traffic light)
πŸ“ Personal homepage: Drivers only need cars and hands, and the pressure comes from the paper_ Cheshen, 18 Fuxue Road_ CSDN blog
πŸ₯‡ Official certification: high-quality creators in the field of artificial intelligence
πŸŽ‰ give the thumbs-up βž• comment βž• Collection = = form a habit (one button three times) πŸ˜‹

⚑ I hope you can give me more support πŸ€—~ Let's come on together 😁

Brush one question every day without saying much. Brush the questions for nearly two years first. From 2020, if you have one together, you can join us!!!

Let's brush the questions together and impact the national competition!!!

Scan code My home page Group QR code on the left of the page.

Joining method: you can add me on the wechat business card below, and then pull you into the group. (remember the note code: I want to win the National Award)

Overview of the 11th Blue Bridge Cup in 2020

These are the questions in 2020. There are two types: result filling and program design. We brush one question every day. There is no problem in saving the game!

Snake filling number (topic)

(total score of this question: 25 points)

Official practice system: https://www.lanqiao.cn/problems/507/learning/

- > [problem description]


- > [enter description]


- > [output description]

The output line contains an integer representing the maximum value that can be obtained.

- > [input / output example]

Input:
1 1
2 1 2
1 1
2 2 2
1 1
1 3
3
1 5 1 2 3 5 8
2 4 2 4 8 15
3 2 5 10

Output:
20

- > [example description]

Inlay the beads in the following way to get the maximum value 18. The type number of inlaid decorative beads is indicated in brackets:

1: (1)
2: (1) (2)
3: (1)
4: (2) (2)
5: (1)
6: (2)

4 skill 1 decorative beads, 4 skill 2 decorative beads W 1 ( 4 ) + W 2 ( 4 ) = 5 + 15 = 20 W_1(4) + W_2(4) = 5 + 15 = 20 W1​(4)+W2​(4)=5+15=20.

analysis

By reading the stem of the question, this question - difficulty medium and above: ⭐⭐⭐⭐

Type of investigation: Number Theory

Knowledge points: dynamic programming + enumeration

analysis:

As it is a blank question, we only need to get one result. The result is an integer.

This problem is very interesting. For engineering men who love to play games, it will be a bit embarrassing if they can't do this kind of buff problem (kidding, the problem is still difficult! ~) first of all, they have to understand the problem stem. In fact, they need to understand it!

Let's take a look at the input example:

code

Python code implementation:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/27 15:04
# @Author: cheshen, 18 Fuxue Road
# @Email   : yurz_control@163.com
# @File    : Day06.py

listlv=[0]*5
listw=[[0 for i in range(8)]for i in range(5)]
listl=[0]*5
listp=[0]*5

#First, use listlv to store the number of decorative holes of each grade (for example, listlv[1]=3 indicates that there are 3 decorative holes of grade 1)
for i in range(6):
    listinput=list(map(int,input().split()))
    for i in range(1,len(listinput)):
        listlv[listinput[i]]+=1

summ=0

m=int(input())
for i in range(m):
    listt=list(map(int,input().split()))
    listl[listt[0]]=listt[0]
    listp[listt[0]]=listt[1]
    listw[listt[0]]=[0]+listt[2:]

#Enumerate the decorative beads of each grade from large to small
for i in range(min(listlv[4],listp[4])+1):
    for j in range(min(listlv[4]+listlv[3]-i,listp[3])+1):
        for k in range(min(listlv[4]+listlv[3]+listlv[2]-j-i,listp[2])+1):
            for l in range(min(listlv[4]+listlv[3]+listlv[2]+listlv[1]-j-i-k,listp[1])+1):
                summ=max(summ,listw[4][i]+listw[3][j]+listw[2][k]+listw[1][l])

print(summ)		# 175

Today's question is verified in the system. If PyCharm can't verify it again~

We can get the result quickly

Today is the sixth day of brushing. The difficulty is medium and high. Welcome to join us, become stronger together, exercise self-discipline together, and go to the national competition together!!!

Today's topic is a little difficult. If you have different solutions, you can leave a message below~

Previous question brushing route:

Question brushing routeDetail
Day-01House plate making
Day-02Looking for 2020
Day-03Running exercise
Day-04Serpentine filling number
Day-05sort

Official question brushing exercise system: http://lx.lanqiao.cn/

❀ Keep reading Paper, keep taking notes, keep learning, and keep brushing LeetCode ❀!!!
Insist on writing questions!!! Impact national competition
⚑To Be No.1

⚑⚑ Ha ha ha ha

⚑ Creation is not easy ⚑, Crossing energy ❀ Follow, collect and like ❀ Three is the best

ღ( Β΄ο½₯α΄—ο½₯` )

❀

Keywords: Python Dynamic Programming

Added by MetaDark on Tue, 01 Mar 2022 01:35:58 +0200