Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int m, n;
- int a[15];
- int dp[15][15];
- int solve(int vt, int gt) {
- if(vt > n) return 1;
- if(dp[vt][gt] != -1) return dp[vt][gt];
- int ans = 0;
- for(int j = 1; j <= m; ++j)
- if(vt == 1 || abs(a[j] - gt) <= 2)
- ans += solve(vt + 1, a[j]);
- return dp[vt][gt] = ans;
- }
- int main() {
- //freopen("in.txt", "r", stdin);
- //freopen("B-DigitCount.inp", "r", stdin);
- //freopen("B-DigitCount.out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- int t; cin >> t;
- for(int test = 1; test <= t; ++test) {
- cin >> m >> n;
- for(int i = 1; i <= m; ++i)
- cin >> a[i];
- memset(dp, -1, sizeof(dp));
- cout << "Case " << test << ": " << solve(1, 0) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment