Advertisement
Kevin_Zhang

Untitled

Apr 18th, 2020
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb emplace_back
  3. using namespace std;
  4. using ll = long long;
  5. const int maxn = 2010;
  6. map<int, map<int, int>> dp[maxn];
  7. map<int, map<int, bool>> did[maxn];
  8. struct info {
  9.     int a, b, c;
  10.     bool operator < (const info &x) const{
  11.         return a > x.a;
  12.     }
  13. };
  14. int res[maxn];
  15. bool out[maxn];
  16. void bf() {
  17.     ofstream fout("pA.out");
  18.     priority_queue<info> togo;
  19.     //queue<info> togo;
  20.     fill(res, res+maxn, maxn+1);
  21.     dp[1][1][0] = 1;
  22.     togo.push({1,1,0});
  23.    
  24.     while (!togo.empty()) {
  25.         auto [a, b, c] = togo.top();
  26. //      if (!out[a-1]) {
  27. //          cerr << a-1 << " : " << res[a-1] << '\n';
  28. //          out[a-1] = true;
  29. //          fout << res[a-1] << ", ";
  30. //      }
  31.  
  32.         togo.pop();
  33.         int val = dp[a][b][c];
  34.         //cerr << a << ' ' << b << ' ' << c << ' ' << " : " << val << '\n';
  35.         auto update = [&](int a, int b, int c, int cost) {
  36.             if (a > 2000) return;
  37.             if (b > c) swap(b, c);
  38.             if (!dp[a][b].count(c))
  39.                 togo.push({a, b, c});
  40.             if (!dp[a][b].count(c) || dp[a][b][c] > cost)
  41.                 dp[a][b][c] = cost;
  42.            
  43.         };
  44.         update(a+b, b, c, val+1);
  45.         update(a+c, b, c, val+1);
  46.         update(a, a, c, val+1);
  47.         update(a, b, a, val+1);
  48.         res[a] = min(res[a], val);
  49.  
  50.     }
  51.     for (int i = 1;i <= 2000;++i)
  52.         cout << res[i] << ",\n", fout << res[i] << ",\n";
  53. }
  54.    
  55. signed main(){
  56.     ios_base::sync_with_stdio(0), cin.tie(0);
  57.     bf();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement