Submission #00151
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include<bits/stdc++.h> #define INF 1<<30 using namespace std; int n; int m[30]; bool f[30]; int blsum = 0; int sum = 0; int memo[15][15000][1000]; int solve( int cnt, int hiki){ if (cnt == n){ return 0; } if (memo[cnt][blsum][hiki] != -1){ return memo[cnt][blsum][hiki]; } int ret = INF; for ( int i=0;i<n;i++){ if (f[i] == false ){ f[i] = true ; blsum += m[i]; ret = min(ret,solve(cnt+1,blsum % 1000) + max(0,m[i] - hiki)); f[i] = false ; blsum -= m[i]; } } return memo[cnt][blsum][hiki] = ret; } int main(){ cin >> n; for ( int i=0;i<n;i++){ cin>>m[i]; } int res = INF; memset (f, false , sizeof (f)); memset (memo,-1, sizeof (memo)); for ( int i=0;i<n;i++){ if (f[i] == false ){ f[i] = true ; blsum += m[i]; res = min(res,solve(1,m[i] % 1000) + m[i]); f[i] = false ; blsum -= m[i]; } } cout << res <<endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0007 - 森田氏の欲求 |
ユーザー名 | ei1437 |
投稿日時 | 2016-05-14 16:16:29 |
言語 | C++ |
状態 | Memory Limit Exceeded |
得点 | 0 |
ソースコード長 | 970 Byte |
最大実行時間 | 1000 ms |
最大メモリ使用量 | 524288 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 13 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
case1.txt | MLE | 1000 ms | 524288 KB |
1
|
case2.txt | MLE | 1000 ms | 524288 KB |
1
|
case3.txt | MLE | 1000 ms | 524288 KB |
1
|
case4.txt | MLE | 1000 ms | 524288 KB |
1
|
case5.txt | MLE | 1000 ms | 524288 KB |
1
|
case6.txt | MLE | 1000 ms | 524288 KB |
1
|
case7.txt | MLE | 1000 ms | 524288 KB |
1
|
case8.txt | MLE | 1000 ms | 524288 KB |
1
|
case9.txt | MLE | 1000 ms | 524288 KB |
1
|
case10.txt | MLE | 1000 ms | 524288 KB |
1
|
case11.txt | MLE | 1000 ms | 524288 KB |
1
|
case12.txt | MLE | 1000 ms | 524288 KB |
1
|
case13.txt | MLE | 1000 ms | 524288 KB |
1
|
case14.txt | MLE | 1000 ms | 524288 KB |
1
|
case15.txt | MLE | 1000 ms | 524288 KB |
1
|
case16.txt | MLE | 1000 ms | 524288 KB |
1
|
case17.txt | MLE | 1000 ms | 524288 KB |
1
|
case18.txt | MLE | 1000 ms | 524288 KB |
1
|
case19.txt | MLE | 1000 ms | 524288 KB |
1
|
case20.txt | MLE | 1000 ms | 524288 KB |
1
|
case21.txt | MLE | 1000 ms | 524288 KB |
1
|
case22.txt | MLE | 1000 ms | 524288 KB |
1
|
case23.txt | MLE | 1000 ms | 524288 KB |
1
|
case24.txt | MLE | 1000 ms | 524288 KB |
1
|
case25.txt | MLE | 1000 ms | 524288 KB |
1
|
case26.txt | MLE | 1000 ms | 524288 KB |
1
|
case27.txt | MLE | 1000 ms | 524288 KB |
1
|
case28.txt | MLE | 1000 ms | 524288 KB |
1
|
case29.txt | MLE | 1000 ms | 524288 KB |
1
|
case30.txt | MLE | 1000 ms | 524288 KB |
1
|
case31.txt | MLE | 1000 ms | 524288 KB |
1
|
case32.txt | MLE | 1000 ms | 524288 KB |
1
|
case33.txt | MLE | 1000 ms | 524288 KB |
1
|
case34.txt | MLE | 1000 ms | 524288 KB |
1
|
case35.txt | MLE | 1000 ms | 524288 KB |
1
|
case36.txt | MLE | 1000 ms | 524288 KB |
1
|
case37.txt | MLE | 1000 ms | 524288 KB |
1
|
case38.txt | MLE | 1000 ms | 524288 KB |
1
|
case39.txt | MLE | 1000 ms | 524288 KB |
1
|
case40.txt | MLE | 1000 ms | 524288 KB |
1
|
sample1.txt | MLE | 1000 ms | 524288 KB |
1
|
sample2.txt | MLE | 1000 ms | 524288 KB |
1
|
sample3.txt | MLE | 1000 ms | 524288 KB |
1
|