P2344
P2344 Generic Cow Protests G
有个显然的转移方程 \(f[i]表示前i头牛的分组方案\)
\(f[i]=\sum~[sum[i]~\ge~sum[j]]~*f[j]~~~(sum[i]>0\ \&\&sum[j]>0)\)
显然就能跑过\(qwq\)
f[0] = 1;
for(int i = 1;i <= n;++i)
if(sum[i] > 0)
for(int j = 0;j < i;++j)
if(sum[j] >= 0 && sum[i] >= sum[j]) (f[i] += f[j]) %= mod;
printf("%lld",f[n]);
\(f[i]=\sum_{j=0}^{i-1}[S_i\ge S_j]*f[j]\)显然是个二维偏序
树状数组维护下标为\(sum[i],f[i]\)的前缀和。对于每个\(f[i]\)为树状数组上\(sum[i]\)的前缀和
注意离散化,下标不能是负的
read(n);
for(int i = 1;i <= n;++i) read(a[i]),sum[i] = sum[i-1] + a[i];
for(int i = 1;i <= n;++i) srt[i] = sum[i];
sort(srt + 1,srt + 1 + n);
int num = unique(srt + 1,srt + n +1) - srt;
for(int i = 0;i <= n;++i) sum[i] = lower_bound(srt,srt + num,sum[i]) -srt+1;
add(sum[0], 1);//f[0] = 1;
int ans=0;
for(int i=1;i<=n;++i){
ans = query(sum[i]);
add(sum[i], ans);
}
printf("%lld\n", ans);
rank 1