Korotkodul

СПБГУ_J_visual

Dec 29th, 2021 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. using namespace std;
  12. using ll = long long;
  13. using ld = long double;
  14. void cv(vector <int> &v){
  15. for (auto x: v) cout<<x<<' ';
  16. cout<<"\n";
  17. }
  18.  
  19. ll n=3;
  20. ll ans = 0;
  21. ll inf = 1e9 + 7;
  22. string two(ll x){
  23. string r = "";
  24. while (x > 0){
  25. r += x % 2 + 48;
  26. x /= 2;
  27. }
  28. reverse(r.begin(), r.end());
  29. while (r.size() < n){
  30. r = '0' + r;
  31. }
  32. return r;
  33. }
  34.  
  35. ll zer(ll x, ll id){
  36. string s = two(x);
  37. //cout<<"s = "<<s<<'\n';
  38. id = n - id - 1;
  39. //cout<<"id = "<<id<<'\n';
  40. ll r = 0;
  41. for (int i = 0; i < id;++i){//cout<<"i = "<<i<<' ';
  42. if (s[i] == '0')r++;
  43. }//cout<<'\n';
  44. return r;
  45. }
  46.  
  47. void cs(string s){
  48. for (int i = 0;i<n;++i){
  49. for (int j=0;j< n;++j){
  50. cout<<s[i*n + j];
  51. }cout<<"\n";
  52. }cout<<"\n";
  53. }
  54.  
  55. void cvs(vector <string> v){
  56. for (auto x: v)cout<<x<<"\n";
  57. cout<<"\n";
  58. }
  59.  
  60. ll zer_s(string s, ll id){
  61. //cout<<"s = "<<s<<'\n';
  62. id = n - id - 1;
  63. //cout<<"id = "<<id<<'\n';
  64. ll r = 0;
  65. for (int i = 0; i < id;++i){//cout<<"i = "<<i<<' ';
  66. if (s[i] == '0')r++;
  67. }//cout<<'\n';
  68. return r;
  69. }
  70.  
  71.  
  72. void vis(string s){
  73. int id = s[s.size() - 1] - 48;
  74. int z = zer_s(s, id);
  75. cout<<"n - "<<z+1<<"\n";
  76. //cout<<s<<"\n";
  77. //cout<<"id = "<<id<<"\n";
  78. //cout<<"z = "<<z<<"\n";
  79. //cout<<"\n";
  80. //cout<<"n "<<
  81. }
  82.  
  83.  
  84. void sh(vector <string> v){//последний символ каждой строки - индекс нового подарка, который мы добавляли -- по этому индексу и нужно расчитывать кол-во вариантов
  85. for (auto s: v){
  86. vis(s);
  87. }
  88. cout<<"\n";
  89. }
  90.  
  91. ll pos=0;
  92.  
  93. ll var(ll msk, ll num, vector <string> s){
  94. num %= inf;
  95. //cout<<"msk = "<<two(msk)<<"\n";
  96. //cout<<"num = "<<num<<"\n";
  97. if (msk == (1 << n) - 1) {
  98. //cs(s);
  99. //cvs(s);
  100. pos++;
  101. //sh(s);
  102. return num;
  103. }
  104. ll pl=0, now,z, add;
  105. for (ll i = 0; i < n; ++i){
  106. //cout<<"i = "<<i<<'\n';
  107. if ( (msk & (1<<i)) != 0) {
  108. //cout<<"skip\n";
  109. continue;
  110. }
  111. z = zer(msk | (1<<i), i);
  112. //cout<<"z = "<<z<<"\n";
  113. now = pow(2, n - z - 1);
  114. now %= inf;
  115. //cout<<"now = "<<now<<"\n";
  116. //cout<<two(msk | (1 << i))<<"\n";
  117. vector <string> v = s;
  118. int ix = i;
  119. char l = ix + 48;
  120. v.push_back(two(msk | 1<<i) + l);
  121. add = var(msk | (1 << i), num * now, v ) % inf;
  122. add %= inf;
  123. pl += add;
  124. pl %= inf;
  125. }
  126. //cout<<"\n";
  127. return pl;
  128. //cout<<"\n";
  129. }
  130.  
  131.  
  132. int main()
  133. {
  134. /*ios::sync_with_stdio(0);
  135. cin.tie(0);
  136. cout.tie(0);*/
  137. cin>>n;
  138. vector <string> v;
  139. ll x = var(0, 1,v);
  140. cout<<"pos = "<<pos<<"\n";
  141. cout<<"res = "<<x<<"\n";
  142. //cout<<"x = "<<x<<"\n";
  143. }
  144.  
Add Comment
Please, Sign In to add comment