Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. long long dp[(1 << 20)];
  4.  
  5. long long
  6. solve()
  7. {
  8.   long long res = 0LL;
  9.  
  10.   dp[0] = 0LL;
  11.   for (int c = 0; c < (1 << 20); ++c)
  12.     dp[c] = 1LL;
  13.   for (int n = 1; n < 18; ++n)
  14.     for (int c = (1 << 20) - 1; c >= 0; --c) {
  15.       dp[c] = 0LL;
  16.       for (int d = 0; d < 10; ++d)
  17.     if (((c >> (d << 1)) & 3) > 0)
  18.       dp[c] += dp[(c & (~(3 << (d << 1)))) | ((((c >> (d << 1)) & 3) - 1) << (d << 1))];
  19.     }
  20.   for (int d = 1; d < 10; ++d)
  21.     res += dp[(((1 << 20) - 1) & ((~(3 << (d << 1))))) | (2 << (d << 1))];
  22.  
  23.   return (res);
  24. }
  25.  
  26. int
  27. main()
  28. {
  29.   printf("Euler #172 : %lld\n", solve());
  30.  
  31.   return (0);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement