solution.java 764 字节
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
import java.util.Scanner;

public class Main {
    static int n, s, a, b;
    static int f[][];
    static int modnum = 100000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        s = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        f = new int[n][n];
        f[0][0] = 1;
        System.out.println(c());
    }

    private static int c() {
        if (n == 1)
            return 1;

        for (int j = 1; j < n; j++)
            for (int i = 0; i < n; i++)
                f[i][j] = (f[g(i - j * a)][j - 1] + f[g(i + j * b)][j - 1]) % modnum;

        return f[g(s)][n - 1];
    }

    private static int g(int v) {
        return ((v % n) + n) % n;
    }
}