题目链接:https://www.luogu.com.cn/problem/P8614
动态规划
这题要是用暴力会超时,根据数据范围来考虑
//没有优化
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#define PII std::pair<ll,ll>
#define ll long long
//ll n;
ll dx[] = {0,0,1,-1};
ll dy[] = {1,-1,0,0};
const ll N = 1e3 + 500;
ll dp[N][N];
const ll mod = 100000007;
/*
x x+a x+a+a x+a+a-b x+a+a-b+a
x
x + a
x + a + a
x + a + a - b
x + a + a - b + a
没有给你第一项
每一项都可以看成:x + n * a + m * b(a是正数b是负数)
*/
ll n,s,a,b;
ll res = 0;
std::map<ll,ll> mp;
ll check(ll a){
return (a % n + n) % n;
}
void solve(){
std::cin >> n >> s >> a >> b;
dp[0][0] = 1;
for(ll i = 1; i < n; i ++){
for(ll j = 0; j < n; j ++){
dp[i][j] = (dp[i - 1][check(j - a * i)] + dp[i - 1][check(j + b * i)]) % mod;
}
}
std::cout << dp[n - 1][check(s)] << "\n";
return ;
}
int main(){
ll t = 1;
while(t --)
solve();
return 0;
}