solution.cpp 760 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
const int mod = 100000007;
int n, s, a, b, up;
ll v;
int dp[2][N * (N + 1) / 2], now;
int ans;
int main()
{
	scanf("%d%d%d%d", &n, &s, &a, &b);
	dp[now][0] = 1;
	for (int i = 1; i < n; ++i) //只有n-1个增量
	{
		now = !now;
		up = i * (i + 1) / 2;
		for (int j = 0; j <= up; ++j) //01背包 容量 方案数
		{
			dp[now][j] = dp[!now][j];
			if (j >= i)
				dp[now][j] = (dp[now][j] + dp[!now][j - i]) % mod;
		}
	}
	for (int i = 0; i <= up; ++i) //s-i*a-(n*(n-1)/2-i)*b 是否被n整除
	{
		v = 1ll * s - 1ll * i * a + 1ll * (up - i) * b;
		if (v % n == 0)
			ans = (ans + dp[now][i]) % mod;
	}
	printf("%d\n", ans);
	return 0;
}