链接

题意:

给出你长度为ABC 216 F - Max Sum Counting(DP+数学+思维)_#include的两个序列ABC 216 F - Max Sum Counting(DP+数学+思维)_#define_02ABC 216 F - Max Sum Counting(DP+数学+思维)_动态规划_03,从中找出子集ABC 216 F - Max Sum Counting(DP+数学+思维)_#define_04从中找子集然后要求

  • ABC 216 F - Max Sum Counting(DP+数学+思维)_动态规划_05

对方案数取模与ABC 216 F - Max Sum Counting(DP+数学+思维)_算法_06

分析:

首先我们看数据范围是5000说明我们可以ABC 216 F - Max Sum Counting(DP+数学+思维)_算法_07
然后我们贪心的想先看ABC 216 F - Max Sum Counting(DP+数学+思维)_#include_08比较小的,这样在看大的就不用看MAX,

然后我们对其按照ABC 216 F - Max Sum Counting(DP+数学+思维)_#include_08排序,然后就好想了, 枚举ABC 216 F - Max Sum Counting(DP+数学+思维)_动态规划_10之间的数,这区间内ABC 216 F - Max Sum Counting(DP+数学+思维)_#include_11

然后我们知道最大值是5000,所以就又用到了背包的思想。状态转移。我们可以用ABC 216 F - Max Sum Counting(DP+数学+思维)_动态规划_12维护和为ABC 216 F - Max Sum Counting(DP+数学+思维)_动态规划_13的方案数。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define x first
#define y second
#define sf scanf
#define pf printf
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
#define debug(x) cout << #x <<": " << x << endl;

const int MOD = 998244353;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, 1, -1};
const int dz[] = {1, -1, 0, 0, 0, 0 };
int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

struct node {
ll x,y;
}q[maxn];
bool cmp(node a,node b){
return a.x<b.x;
}
ll dp[maxn];
ll n;
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>q[i].x;
for(int i=1;i<=n;i++)cin>>q[i].y;

sort(q+1,q+1+n,cmp);

ll ans=0;
dp[0]=1;
for(int i=1;i<=n;i++){
for(int j=q[i].y;j<=q[i].x;j++){
ans=(ans+dp[j-q[i].y])%MOD;
}
for(int j=5000;j>=q[i].y;j--){
dp[j]=(dp[j]+dp[j-q[i].y])%MOD;
}
}
cout<<ans<<endl;
}

int main()
{
//init();
ll t = 1;
//scanf("%lld",&t);
while(t--)
{
solve();
}
return 0;
}