牛客网华为机试题之Python解法 第1题 字符串最后一个单词的长度 a = input().split(" ") print(len(a[-1])) 第2题 计算字符个数 a = input() b = input() print(a.lower().count(b.lower())) 第3题 明明的随机数 while True: try: num = int(input()) data = [] for i in range(num): data.append(int(input(…
是我想复杂了 首先发现大于关系构成了一棵二叉树的结构,于是树形dp 设f[i]为i点的方案数,si[i]为i点的子树大小,递推式是\( f[i]=f[i*2]*f[i*2+1]*C_{si[i]-1}^{si[i*2]} \) 组合数用Lucas求 #include<iostream> #include<cstdio> using namespace std; long long n,p,f[5000005],jc[5000005],s[5000005]; long long ks…
You are given a rooted tree with n nodes. The nodes are numbered 1..n. The root is node 1, and m of the nodes are colored red, the rest are black. You would like to choose a subset of nodes such that there is no node in your subset which is an ancest…