题意:给定两个递增数列A和B,构造一个ai <= ci <= bi 的递增数列C,询问满足条件的C的个数。
普通dp会超时,用前缀和优化
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) l=3010 dp=[[0]*l for _ in range(n+1)] dp[0][0]=1 for i in range(n): for j in range(l): if dp[i][j]==0: continue dp[i+1][max(j,a[i])]+=dp[i][j] dp[i+1][b[i]+1]-=dp[i][j] for j in range(l-1): dp[i+1][j+1]+=dp[i+1][j] dp[i+1][j+1]%=998244353 print(sum(dp[-1])%998244353)
标签:前缀,Arrays,Two,int,range,Between,input,dp From: https://www.cnblogs.com/trave11er/p/17552399.html