Advertisement
Korotkodul

ИТМО_отбор_dp

Sep 20th, 2022 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 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. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42. int N;
  43.  
  44. bool sh=1;
  45.  
  46. void cvp(vector <pii> a){
  47.     for (auto p: a){
  48.         cout<<p.first<<' '<<p.second<<"\n";
  49.     }
  50.     cout<<"\n";
  51. }
  52.  
  53. string to(int x){
  54.     string r="";
  55.     while (x > 0){
  56.         r += x%2+'0';
  57.         x/=2;
  58.     }
  59.     reverse(r.begin(), r.end());
  60.     while (r.size() < N){
  61.         r = '0' + r;
  62.     }
  63.     return r;
  64. }
  65.  
  66. bool log(bool a, bool b, bool c){
  67.     return !b || a&&c || (!a)&&(!c);
  68. }
  69.  
  70. bool ok(string s){
  71.     if (sh) cout<<s<<"\n";
  72.     int n = s.size();
  73.     for (int i = 0; i < n - 2; ++i){
  74.         bool a,b,c;
  75.         a = s[i]-'0';
  76.         b=s[i+1]-'0';
  77.         c = s[i+2]-'0';
  78.         if (log(a,b,c) ){
  79.             if (s[i+2] != s[n-1]) continue;
  80.             else {
  81.             if (sh) cout<<"OK\n";
  82.                return 1;
  83.             }
  84.         }
  85.         else{
  86.             if (sh) cout<<"NO\n";
  87.             return 0;
  88.         }
  89.     }
  90. }
  91.  
  92. int f(int n){
  93.     int ans=0;
  94.     if (sh){
  95.         cout<<"n = "<<n<<"\n";
  96.     }
  97.     for (int i = 0; i < pow(2, n); ++i){
  98.         string s = to(i);
  99.         if (ok(s))ans++;
  100.     }
  101.     return ans;
  102. }
  103.  
  104. int main()
  105. {
  106.     /*ios::sync_with_stdio(0);
  107.     cin.tie(0);
  108.     cout.tie(0);*/
  109.     /*int n=10;
  110.     N=n;
  111.     while (f(n) != 611 &&n <11){
  112.         if (sh){
  113.             cout<<"n = "<<n<<"\n";
  114.             cout<<f(n)<<"\n";
  115.         }
  116.         n++;
  117.         N=n;
  118.     }*/
  119.     vector <vector<int>> dp(20, vector <int> (6));
  120.     for (int i = 0; i < 6; ++i) dp[3][i] = 1;
  121.     int i = 3;
  122.     while (1){
  123.         int s=0;
  124.         for (int j = 0; j < 6; ++j) s += dp[i][j];
  125.         if (s == 611){
  126.             cout<<"ans = "<<i<<"\n";
  127.             break;
  128.         }
  129.         i++;
  130.         dp[i][0] = dp[i - 1][0] + dp[i - 1][3];
  131.         dp[i][1] = dp[i][0];
  132.         dp[i][2] = dp[i-1][1] + dp[i-1][4];
  133.         dp[i][3] = dp[i-1][2];
  134.         dp[i][4] = dp[i][3];
  135.         dp[i][5] = dp[i-1][5];
  136.     }
  137.  
  138.     //cout<<n;
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement