虽然很简单,但是统一一下板子,以防写错
D - Between Two Arrays (atcoder.jp)
题意:
思路:
直接DP即可
Code:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mxn=3e3+10;
const int mxe=3e3+10;
const int Inf=0x3f3f3f3f;
const int mod=998244353;
int N;
int a[mxn],b[mxn],c[mxn];
int pre[mxn];
int dp[mxn][mxn];
void solve(){
cin>>N;
for(int i=1;i<=N;i++) cin>>a[i];
for(int i=1;i<=N;i++) cin>>b[i];
for(int i=a[1];i<=b[1];i++){
dp[1][i]=(dp[1][i]+1)%mod;
}
for(int i=2;i<=N;i++){
pre[0]=dp[i-1][0];
for(int k=1;k<=3000;k++){
pre[k]=(pre[k-1]+dp[i-1][k])%mod;
}
for(int j=1;j<=3000;j++){
if(j<a[i]||j>b[i]) continue;
dp[i][j]=(dp[i][j]+pre[j]-pre[max(j,a[i-1])])%mod;
}
}
int ans=0;
for(int i=a[N];i<=b[N];i++) ans=(ans+dp[N][i])%mod;
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int __=1;//cin>>__;
while(__--)solve();return 0;
}