結果

問題 No.286 Modulo Discount Store
ユーザー deark1414deark1414
提出日時 2017-10-06 15:46:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 53,568 KB
実行使用メモリ 5,672 KB
最終ジャッジ日時 2023-08-10 16:57:24
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,400 KB
testcase_01 AC 3 ms
5,452 KB
testcase_02 AC 6 ms
5,416 KB
testcase_03 AC 2 ms
5,452 KB
testcase_04 AC 3 ms
5,416 KB
testcase_05 AC 2 ms
5,412 KB
testcase_06 AC 8 ms
5,304 KB
testcase_07 AC 3 ms
5,472 KB
testcase_08 AC 2 ms
5,456 KB
testcase_09 AC 3 ms
5,412 KB
testcase_10 AC 4 ms
5,408 KB
testcase_11 AC 2 ms
5,468 KB
testcase_12 AC 2 ms
5,416 KB
testcase_13 AC 6 ms
5,304 KB
testcase_14 AC 3 ms
5,332 KB
testcase_15 AC 3 ms
5,372 KB
testcase_16 AC 3 ms
5,396 KB
testcase_17 AC 16 ms
5,316 KB
testcase_18 AC 4 ms
5,396 KB
testcase_19 AC 3 ms
5,620 KB
testcase_20 AC 4 ms
5,540 KB
testcase_21 AC 3 ms
5,408 KB
testcase_22 AC 3 ms
5,336 KB
testcase_23 AC 5 ms
5,476 KB
testcase_24 AC 3 ms
5,604 KB
testcase_25 AC 3 ms
5,408 KB
testcase_26 AC 3 ms
5,412 KB
testcase_27 AC 3 ms
5,416 KB
testcase_28 AC 9 ms
5,304 KB
testcase_29 AC 3 ms
5,352 KB
testcase_30 AC 2 ms
5,452 KB
testcase_31 AC 3 ms
5,332 KB
testcase_32 AC 2 ms
5,396 KB
testcase_33 AC 3 ms
5,400 KB
testcase_34 AC 2 ms
5,404 KB
testcase_35 AC 3 ms
5,472 KB
testcase_36 AC 2 ms
5,532 KB
testcase_37 AC 4 ms
5,412 KB
testcase_38 AC 3 ms
5,460 KB
testcase_39 AC 9 ms
5,332 KB
testcase_40 AC 3 ms
5,304 KB
testcase_41 AC 2 ms
5,404 KB
testcase_42 AC 3 ms
5,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string.h>

using namespace std;

const int kind = 1 << 15;
int dp[15+1][kind + 1];

int main(){
	memset(dp,0,sizeof(dp));
	int n;
	cin >> n;
	
	int m[15];
	for(int i = 0;i < n;i++){
		cin >> m[i];
	}
	
	for(int i = 0;i < n;i++){
		dp[1][0+(1 << i)] = m[i];
	}
	
	for(int i = 1;i < n;i++){
		for(int j = 0;j < (1 <<n);j++){
			if(dp[i][j] != 0){
				for(int k = 0;k < n;k++){
					if((j >> k) % 2 == 0){
						int dis=0;
						for(int l = 0;l < n;l++){
							if((j >> l) % 2 == 1) dis += m[l];
						}
						dis = dis % 1000;
						if(dp[i+1][j + (1 << k)] != 0){
							dp[i+1][j + (1 << k)] = min(dp[i+1][j + (1 << k)],dp[i][j] + max(0,m[k]-dis));
						}else{
							dp[i+1][j + (1 << k)] = dp[i][j] + max(0,m[k]-dis);
						}
					}
				}
			}
		}
	}
	
	int ans = 1e9;
	for(int i = 0;i < 1<<n;i++){
		if(dp[n][i] != 0)ans = min(ans,dp[n][i]);
	}
	
	cout << ans << endl;
	return 0;
}
0