第二题 str1=input() str2=input() T=int(input()) n,m=len(str1),len(str2) dp=[[0]*(n+1) for _ in range(m+1)] for j in range(1,m+1): dp[0][j]=j for i in range(1,n+1): for j in range(1,m+1): if str1[-i]<str2[-j]: dp[i][j]=i+j else: dp[i][j]=max(dp[i-1][j],dp[i][j-1]) for t in range(T): i,j=input().split() i,j=int(i),int(j) print(dp[n-i+1][m-j+1])
采果子 n,m = list(map(int,input().split())) w = list(map(int,input().split())) w = sorted(w) Q = [] for i in range(m): Q.append(int(input())) mmap = {} for i in range(n): for j in range(i+1,n): mmap[w[j]-w[i]] = (w[i],w[j]) for q in Q: data = mmap.get(q,None) if data: print(f"{data[0]} {data[1]}") else: print("-1 -1")
求教采果子这样做有什么问题 def f(nums,w): numset=set() for num in nums: if num+w in numset: return num,num+w elif num-w in numset: return num-w,num else: numset.add(num) return -1,-1
import sys a = sys.stdin.readline().strip().split(' &(5528)#39;) n,m = int(a[0]),int(a[1]) ws = sys.stdin.readline().strip().split(' &(5528)#39;) ws = [int(i) for i in ws] ws = sorted(ws,key=lambda x:-x) ws = [abs(x) for x in ws] for i in range(m): w = int(sys.stdin.readline().strip()) for j in range(n): diff = ws[j] - w if diff in ws[j+1:]: print(str(ws[j])+' &(5528)#39;+str(diff)) break if j == n-1:print('-1 -1&(12174)#39;) 我这个是哪里复杂了呢?超时了