DuongNhi99

B - DigitCount (24-11)

Dec 10th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int m, n;
  5. int a[15];
  6. int dp[15][15];
  7.  
  8. int solve(int vt, int gt) {
  9.     if(vt > n) return 1;
  10.  
  11.     if(dp[vt][gt] != -1) return dp[vt][gt];
  12.  
  13.     int ans = 0;
  14.     for(int j = 1; j <= m; ++j)
  15.         if(vt == 1 || abs(a[j] - gt) <= 2)
  16.             ans += solve(vt + 1, a[j]);
  17.  
  18.     return dp[vt][gt] = ans;
  19. }
  20.  
  21. int main() {
  22.     //freopen("in.txt", "r", stdin);
  23.     //freopen("B-DigitCount.inp", "r", stdin);
  24.     //freopen("B-DigitCount.out", "w", stdout);
  25.     ios_base::sync_with_stdio(false);
  26.     cin.tie(NULL); cout.tie(NULL);
  27.  
  28.     int t; cin >> t;
  29.     for(int test = 1; test <= t; ++test) {
  30.         cin >> m >> n;
  31.         for(int i = 1; i <= m; ++i)
  32.             cin >> a[i];
  33.  
  34.         memset(dp, -1, sizeof(dp));
  35.         cout << "Case " << test << ": " << solve(1, 0) << '\n';
  36.     }
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment