Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int T;
- cin >> T;
- for (int t = 0; t < T; t++) {
- long long n, l, r, mod;
- cin >> n >> l >> r >> mod;
- vector < vector < long long > > dp(n + 1, vector < long long >(10, 0));
- if (n == 1) {
- cout << 10 << "\n";
- continue;
- }
- for (int i = 1; i < 10; i++) {
- dp[1][i] = 1;
- }
- for (int i = 2; i <= n; i++) {
- for (int j = 0; j < 10; j++) {
- for (int x = 0; x < 10; x++) {
- if (abs(j - x) >= l && abs(j - x) <= r) {
- dp[i][j] += dp[i - 1][x];
- dp[i][j] %= mod;
- }
- }
- }
- }
- long long ans = 0;
- for (int i = 0; i <= 9; i++) {
- ans += dp[n][i];
- ans %= mod;
- }
- cout << ans << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement