Atcoder M
题意 给你n个人 然后每个人都有个吃糖上线
问把 K 个糖分给 n 个人的方案数
我们首先容易得到转移方程 dp[i][j] 代表到第 i 个人为止 吃了 j 颗糖的方案数
那么容易想到O(nkk)的转移方程
int L = j + 1;
int R = j + min(k-j,up_to);
for(int i = L;i<=R;++i)
add(dp[i],tmp);
那么我们发现利用一下差分前缀和的trick
不就可以减少一个 k 的复杂度了么
代码如下
for(int j = k;j>=0;--j)
{
int tmp = dp[j];
int L = j + 1;
int R = j + min(k-j,up_to);
if(L<=R)
{
add(sum[L],tmp);
if(R+1<=k)
{
sub(sum[R+1],tmp);
}
}
}
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>