不是很会,记录一下
最后的下边换成形同下标
1 * d1 + 2 * d2 + 3 * d3 + … +(n - 1)dn-1 = s(mod(n))
import java.util.*;
public class Main {
static final int N = 1010, MOD = 100000007;
static int[][] f = new int[N][N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), s = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
f[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j < n; j++)
f[i][j] = (f[i - 1][get_mod(j - i * a, n)] + f[i - 1][get_mod(j + b * i, n)]) % MOD;
System.out.println(f[n - 1][get_mod(s, n)]);
}
static int get_mod(int a, int m) {
return (a % m + m) % m;
}
}