結果

問題 No.286 Modulo Discount Store
ユーザー airis
提出日時 2015-10-10 15:12:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 81,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-21 06:14:01
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)

using namespace std;

const int INF = (int)(1e+9 + 7);

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int N;
int M[20];
int dp[1 << 16];

int sum(int S) {
	int res = 0;
	for (int i = 0; i < N; i++) {
		if ((S & (1 << i)) == 0) continue;
		res += M[i];
		res %= 1000;
	}
	return res;
}

void solve() {
	fill(dp, dp + (1 << 16), INF);
	dp[0] = 0;
	for (int S = 1; S < (1 << N); S++) {
		for (int b = 0; b < N; b++) {
			if ((S & (1 << b)) == 0) continue;
			int T = S & (~(1 << b));
			dp[S] = min(dp[S], dp[T] + max(0, M[b] - sum(T)));
		}
	}
	cout << dp[(1 << N) - 1] << endl;
}

int main() {
	cin >> N;
	rep(i, N) cin >> M[i];
	solve();
	return 0;
}


0