Advertisement
Emiliatan

d795

Aug 12th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. /* d795            */
  2. /* AC (80ms, 92KB) */
  3. #pragma warning( disable : 4996 )
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <cstdint>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <tuple>
  10. #define ios_jazz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  11.  
  12. using namespace std;
  13.  
  14. using int16 = short;
  15. using uint16 = unsigned short;
  16. using uint = unsigned int;
  17. using int64 = long long;
  18. using uint64 = unsigned long long;
  19. using pii = pair<int, int>;
  20.  
  21. /* main code */
  22. inline int convert(char ch) noexcept
  23. {
  24.     return (ch >= '0' && ch <= '9' ? ch - '0' : ch - 'A' + 10);
  25. }
  26.  
  27. constexpr int MAXN = 17;
  28. uint64 DP[MAXN][MAXN], ans;
  29. char s[MAXN]{1};
  30. uint len, Index = 0;
  31.  
  32. int main()
  33. {
  34.     while (~scanf("%s", s + 1))
  35.     {
  36.         memset(DP, 0, sizeof(uint64) * MAXN * MAXN);
  37.         ans = 0;
  38.         len = strlen(s) - 1;
  39.  
  40.         if (s[1] == '?')
  41.             for (int i = 1; i <= len; ++i) DP[1][i] = 1;
  42.         else
  43.             DP[1][convert(s[1])] = 1;
  44.  
  45.         for (Index = 2; Index <= len; ++Index)
  46.             if (s[Index] == '?')
  47.             {
  48.                 for (int j = 1; j <= len; ++j)
  49.                     for (int k = 1; k <= len; ++k)
  50.                         if (abs(j - k) >= 2)
  51.                             DP[Index][j] += DP[Index - 1][k];
  52.             }
  53.             else
  54.             {
  55.                 s[Index] = convert(s[Index]);
  56.                 for (int k = 1; k <= len; ++k)
  57.                     if (abs(s[Index] - k) >= 2)
  58.                         DP[Index][s[Index]] += DP[Index - 1][k];
  59.             }
  60.  
  61.         for (int i = 1; i <= len; ++i)
  62.             ans += DP[len][i];
  63.  
  64.         printf("%llu\n", ans);
  65.     }
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement