注意:下标越界
  • Tip

    高维数组,下标越界,没有Error,只是寄

  • P2761 软件补丁问题

    • Code

      #include<bits/stdc++.h>
      #define int long long
      #define cint const int&
      using namespace std;
      using pii = pair<int, int>;
      const int maxn = 25, maxm = 1001;
      int dis[1ll << maxn], t[maxm], n, m;
      char aft[maxm][maxn], bef[maxm][maxn];
      inline bool check(cint i, cint bug) {
          for (int j = 0; j < n; ++j) {
              if (bef[i][j] == '-' && (bug & (1ll << j)))
                  return 0;
              if (bef[i][j] == '+' && !(bug & (1ll << j)))
                  return 0;
          }
          return 1;
      }
      inline void update(cint i, int& bug) {
          for (int j = 0; j < n; ++j) {
              if (aft[i][j] == '+')
                  bug |= (1ll << j);
              else if (aft[i][j] == '-')
                  bug &= ~(1ll << j);
          }
      }
      bool vis[1ll << maxn];
      priority_queue<pii, vector<pii>, greater<pii>> pq;
      
      inline void dijkstra(cint x) {
          memset(vis, 0, sizeof(vis[0]) << n);
          memset(dis, 0x3f3f3f3f, sizeof(dis[0]) << n);
          while (!pq.empty()) {
              pq.pop();
          }
          dis[x] = 0;
          pq.push({ 0,x });
          while (!pq.empty()) {
              const auto [w, v] = pq.top();
              pq.pop();
              if (vis[v]) continue;
              vis[v] = 1;
              if (v == 0)return;
              for (int i = 1; i <= m; ++i) {
                  if (check(i, v)) {
                      auto nxtv = v;
                      update(i, nxtv);
                      auto nxtw = w + t[i];
                      if (nxtw < dis[nxtv]) {
                          dis[nxtv] = nxtw;
                          pq.push({ nxtw,nxtv });
                      }
                  }
              }
          }
      }
      int tc = 0;
      signed main() {
          cin >> n >> m;
          for (int i = 1; i <= m; ++i)
              cin >> t[i] >> bef[i] >> aft[i];
          dijkstra((1ll << n) - 1);
          if (vis[0])cout << dis[0];
          else cout << 0;
      }
      
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇