Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11.  
  12. vector<ll> a;
  13. vector<vector<map<pair<ll, ll>, ll> > > dp;
  14.  
  15. //#define _DEBUG
  16. //#define _FILE
  17.  
  18. void print(ll it) {
  19. #ifdef _DEBUG
  20. for (ll i = 0; i < 10; i++) {
  21. cout << dp[it][i].size() << "->";
  22. for (auto k = dp[it][i].begin(); k != dp[it][i].end(); k++) {
  23. cout << k->first.first << ';' << k->first.second << ':' << k->second << '|';
  24. }
  25. cout << "|||";
  26. }
  27. cout << endl;
  28. #endif
  29. }
  30.  
  31. using namespace std;
  32. int main() {
  33. #ifdef _FILE
  34. freopen("input.txt", "r", stdin);
  35. freopen("output.txt", "w", stdout);
  36. #endif
  37. cin.tie(0);
  38. ios_base::sync_with_stdio(0);
  39.  
  40. ll n;
  41. cin >> n;
  42.  
  43. dp.resize(n);
  44. a.resize(n);
  45.  
  46. for (ll i = 0; i < n; i++) {
  47. cin >> a[i];
  48. dp[i].resize(10);
  49. }
  50. dp[0][a[0] % 10][make_pair(0, a[0] % 10)] = 1;
  51. print(0);
  52.  
  53. for (ll i = 1; i < n; i++) {
  54. for (ll j = 0; j < 10; j++) {
  55. for (auto k = dp[i - 1][j].begin(); k != dp[i - 1][j].end(); k++) {
  56. ll pr_sum = k->first.first;
  57. ll pr_mult = k->first.second;
  58. ll pr_count = k->second;
  59.  
  60. //prod
  61. ll pos = (pr_mult * a[i] + pr_sum) % 10;
  62. ll x = (pr_mult * a[i]) % 10;
  63. dp[i][pos][make_pair(pr_sum, x)] += pr_count;
  64. dp[i][pos][make_pair(pr_sum, x)] %= (1000000007);
  65.  
  66. //summ
  67. pos = (pr_mult + a[i] + pr_sum) % 10;
  68. x = (pr_mult + pr_sum) % 10;
  69. dp[i][pos][make_pair(x, a[i] % 10)] += pr_count;
  70. dp[i][pos][make_pair(x, a[i] % 10)] %= (1000000007);
  71. }
  72. }
  73. print(i);
  74. }
  75.  
  76. for (ll i = 0; i < 10; i++) {
  77. ll res = 0;
  78. for (auto it = dp[n - 1][i].begin(); it != dp[n - 1][i].end(); it++) {
  79. res += it->second;
  80. }
  81. cout << res % (1000000007)<< ' ';
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement