結果

問題 No.286 Modulo Discount Store
ユーザー k
提出日時 2021-03-17 14:59:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 194,180 KB
最終ジャッジ日時 2025-01-19 17:54:55
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int INF = 1<<30;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> cost(n);
  for (int i = 0; i < n; i++)
    cin >> cost[i];
  
  vector<int> dp(1<<n);
  
  for (int mask = 1; mask < 1<<n; mask++) {
    dp[mask] = INF;
    int sum = 0;
    for (int i = 0; i < n; i++)
      if (mask & 1 << i)
        sum += cost[i];
    for (int i = 0; i < n; i++) {
      if (mask & 1 << i) {
        int nask = mask ^ (1 << i);
        int discount = (sum - cost[i]) % 1000;
        dp[mask] = min(dp[mask], dp[nask] + max(0, cost[i] - discount));
      }
    }
  }

  cout << dp[(1<<n) - 1] << endl;
  
  
  return 0;
}
0