inputstr ="7,3,6,2,5,1,9"#某个用例nums = [int(i)for i in inputstr.split(',')]dp = [0for i inrange(len(nums))]ans =0n =len(nums)for i inrange(n): dp[i]=1for j inrange(i):if nums[j]<= nums[i]:#注意与求递增序列稍微不同,多了等号 dp[i]=max(dp[i], dp[j] +1) ans =max(dp[i], ans)if ans ==0:print(1)else:print(ans)result = []for i inrange(1, max(dp)+1): result.append([])for j inrange(len(dp)):if dp[j]== i: result[i-1].append(str(nums[j]))for x in result:print(','.join(x))