\(\rm Description\)

\(\rm Link.\)

\(\text{Solution}\)

就挺奇妙的。

可以发现,当 \(i\le \sqrt n\) 时这是一个多重背包问题,当 \(i>\sqrt n\) 时因为有 \(i^2>n\),这其实是一个完全背包问题。

那就分类做吧:

  • \(i\le \sqrt n\)

    先写出方程:

    \[f_j=\sum_k f_{j-k i} \]

    直接用前缀和优化到 \(\mathcal O(n\sqrt n)\).

  • \(i>\sqrt n\)

    继续挖掘题目的性质,我们发现题目的物品还有一个和普通完全背包不一样的地方:物品体积是连续的。这样就保证了在 \([\sqrt n+1,n]\) 的物品都是随便取的。

    定义 \(f_{i,j}\) 为选了 \(i\) 个物品(不是种类),总和为 \(j\) 的方案总数。就有一个非常神奇的式子:

    \[f_{i,j}=f_{i-1,j-(\sqrt n+1)}+f_{i,j-i} \]

    转移分别是加一个体积为 \(\sqrt n+1\) 的物品,或是 \(i\) 个物品每个都 \(+1\). 时间复杂度 \(\mathcal O(n\sqrt n)\).

最后把两种情况合并就行了,注意 \(\rm ans\) 赋初值为 \(f_n\).

\(\text{Code}\)

#include <cstdio>

#define rep(i,_l,_r) for(register signed i=(_l),_end=(_r);i<=_end;++i)
#define fep(i,_l,_r) for(register signed i=(_l),_end=(_r);i>=_end;--i)
#define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
#define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
#define print(x,y) write(x),putchar(y)

template <class T> inline T read(const T sample) {
    T x=0; int f=1; char s;
    while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
    while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
    return x*f;
}
template <class T> inline void write(const T x) {
    if(x<0) return (void) (putchar('-'),write(-x));
    if(x>9) write(x/10);
    putchar(x%10^48);
}
template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
template <class T> inline T fab(const T x) {return x>0?x:-x;}
template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;}
template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;}
template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}

#include <cmath>

const int maxn=1e5+5,mod=23333333;

int n,m,f[maxn],s[maxn],g[320][maxn],ans;

int main() {
	n=read(9); m=sqrt(n);
	f[0]=1;
	rep(i,1,m) {
		rep(j,0,i-1) s[j]=f[j];
		rep(j,i,n) s[j]=(s[j-i]+f[j])%mod;
		rep(j,0,n) {
			f[j]=s[j];
			if(j-i*(i+1)>=0) f[j]=(f[j]-s[j-i*(i+1)]+mod)%mod;
		}
	}
	g[0][0]=1; ans=f[n];
	rep(i,1,m) {
		rep(j,i*(m+1),n) {
			g[i][j]=(g[i-1][j-m-1]+g[i][j-i])%mod;
			ans=(ans+1ll*g[i][j]*f[n-j]%mod)%mod;
		}
	}
	print(ans,'\n');
	return 0;
} 
posted on 2020-11-26 17:13  Oxide  阅读(113)  评论(0编辑  收藏  举报