That's the chunk of the routine. Less than equals n−−√\sqrt N direct violent backpack. Greater than n−−√\sqrt n can be found in the maximum number of n−−√\sqrt N, so use a rotating volume backpack.
Total complexity O (nn−−√) O (n\sqrt N)
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=50005,mod=1e9+7;
int N,f0[maxn],b,f[maxn][230],f1[maxn],ans;
int main () {
freopen ("51nod1259.in", "R", stdin);
Freopen ("51nod1259.out", "w", stdout);
scanf ("%d", &n); B=SQRT (n) +1;
F0[0]=1;
for (int i=1;i<=b-1;i++) for
(int j=i;j<=n;j++) (f0[j]+=f0[j-i])%=mod;
F[b][1]=1;
for (int i=b;i<=n;i++) (
int j=1;j<=b;j++) {
(f[i][j]+=f[i-b][j-1])%=mod;
if (i-j>=0) (f[i][j]+=f[i-j][j])%=mod;
(F1[i]+=f[i][j])%=mod;
Ans= (F0[n]+f1[n])%mod;
for (int i=1;i<=n-1;i++) (ans+= (LL) f0[i]*f1[n-i]%mod)%=mod;
printf ("%d\n", ans);
return 0;
}