第十五届蓝桥杯Python大学B组国赛题解系列–第一题
题目
题解
- 这是一个很简单的枚举问题,应该是为了让国赛选手都能拿优秀奖以上(国赛不是零分卷就起码有优秀奖),才出的签到题。
- 每个题的得分只有零分和满分两个情况,那么总的也就 2 10 2^{10} 210种情况,用set()集合存储去重,写for循坏或者des来枚举,最后set()的长度就是最终结果。
a=[5,5,10,10,15,15,20,20,25,25]
aset=set()
def dfs(depth,res):
if depth==len(a):
aset.add(res)
return
res1=res
res2=res
res1+=a[depth]
dfs(depth+1,res1)
dfs(depth+1,res2)
dfs(0,0)
print(aset)
# {0, 130, 5, 135, 10, 140, 15, 145, 20, 150, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125}
print(len(aset))
# 31
- 由于也可以直接用手枚举,找0-150中5的倍数的数,能否找出解。
(1)0:0
(2)5:5
(3)10:5+5
(4)15:10+5
(5)20:10+10
(6)25:25
(7)30:10+20
(8)35:25+10
(9)40:20+20
(10)45:25+20
(11)50:25+25
(12)55:25+25+5
(13)60:25+25+10
(14)65:25+25+15
(15)70:25+25+20
(16)75:25+25+20+5
(17)80:25+25+20+10
(18)85:25+25+20+10+5
(19)90:25+25+20+20
(20)95:25+25+20+20+5
(21)100:25+25+20+20+10
(22)105:25+25+20+20+10+5
(23)110:25+25+20+20+10+10
(24)115:25+25+20+20+10+10+5
(25)120:25+25+20+20+15+15
(26)125:25+25+20+20+15+15+5
(27)130:25+25+20+20+15+15+10
(28)135:25+25+20+20+15+15+10+5
(29)140:25+25+20+20+15+15+10+10
(30)145:25+25+20+20+15+15+10+10+5
(31)145:25+25+20+20+15+15+10+10+5+5
如果您觉得对您有帮助,就请给我点个赞吧!Thanks♪(・ω・)ノ