結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-10 03:46:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 656 bytes |
| コンパイル時間 | 1,832 ms |
| コンパイル使用メモリ | 194,672 KB |
| 最終ジャッジ日時 | 2025-01-19 13:10:55 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int dp[1<<15];
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n,t;
vector <int> v;
cin >> n;
for(int i=0;i<n;i++)
{
cin >> t;
v.push_back(t);
}
for(int i=0;i<(1<<n);i++)
{
dp[i] = 1e9;
}
dp[0] = 0;
for(int i=0;i<(1<<n);i++)
{
int sum = 0;
for(int j=0;j<n;j++)
{
if((i&(1<<j)))
{
sum += v[j];
}
}
for(int j=0;j<n;j++)
{
if((i&(1<<j))==0)
{
int cost = v[j] - (sum%1000);
if(cost < 0)
{
cost = 0;
}
dp[i + (1<<j)] = min(dp[i + (1<<j)],dp[i] + cost);
}
}
}
cout << dp[(1<<n)-1] << '\n';
return 0;
}