Submission #00158


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
int n;
int m[20];
int dp[2000][1 << 16];
int solve(int teka,int bit){
int rec = 200000,cnt,ans;
for(cnt = 0; cnt < n; cnt++){
if(!(bit & 1 << cnt))break;
}
if(cnt == n){
return 0;
}
if(dp[teka][bit] != -1)return dp[teka][bit];
for(int i = 0; i < n; i++){
if(!(bit & 1 << i)){
if(m[i] - teka < 0 )ans = 0;
else ans = m[i] - teka;
rec = min(rec,solve((teka + m[i])%1000,bit | 1 << i) + ans);
}
}
return dp[teka][bit] = rec;
}
int main(){
memset(dp,-1,sizeof(dp));
cin >> n;
for(int i =0; i < n; i++){
cin >> m[i];
}
cout << solve(0,0) << endl;
}

ステータス

項目 データ
問題 0007 - 森田氏の欲求
ユーザー名 ei1501
投稿日時 2016-05-14 16:25:17
言語 C++11
状態 Accepted
得点 13
ソースコード長 691 Byte
最大実行時間 86 ms
最大メモリ使用量 512760 KB

セット

セット 得点 Cases
1 ALL 13 / 13 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
case1.txt AC 70 ms 512476 KB
1
case2.txt AC 74 ms 512476 KB
1
case3.txt AC 72 ms 512476 KB
1
case4.txt AC 68 ms 512760 KB
1
case5.txt AC 68 ms 512712 KB
1
case6.txt AC 71 ms 512688 KB
1
case7.txt AC 73 ms 512660 KB
1
case8.txt AC 67 ms 512644 KB
1
case9.txt AC 68 ms 512628 KB
1
case10.txt AC 68 ms 512456 KB
1
case11.txt AC 70 ms 512556 KB
1
case12.txt AC 72 ms 512664 KB
1
case13.txt AC 81 ms 512640 KB
1
case14.txt AC 77 ms 512488 KB
1
case15.txt AC 74 ms 512592 KB
1
case16.txt AC 77 ms 512440 KB
1
case17.txt AC 84 ms 512416 KB
1
case18.txt AC 86 ms 512520 KB
1
case19.txt AC 72 ms 512496 KB
1
case20.txt AC 77 ms 512448 KB
1
case21.txt AC 77 ms 512552 KB
1
case22.txt AC 84 ms 512524 KB
1
case23.txt AC 76 ms 512500 KB
1
case24.txt AC 79 ms 512608 KB
1
case25.txt AC 70 ms 512584 KB
1
case26.txt AC 69 ms 512560 KB
1
case27.txt AC 69 ms 512544 KB
1
case28.txt AC 70 ms 512524 KB
1
case29.txt AC 78 ms 512500 KB
1
case30.txt AC 68 ms 512584 KB
1
case31.txt AC 67 ms 512560 KB
1
case32.txt AC 74 ms 512536 KB
1
case33.txt AC 67 ms 512516 KB
1
case34.txt AC 67 ms 512496 KB
1
case35.txt AC 70 ms 512608 KB
1
case36.txt AC 81 ms 512584 KB
1
case37.txt AC 72 ms 512692 KB
1
case38.txt AC 70 ms 512672 KB
1
case39.txt AC 70 ms 512652 KB
1
case40.txt AC 70 ms 512736 KB
1
sample1.txt AC 72 ms 512732 KB
1
sample2.txt AC 68 ms 512704 KB
1
sample3.txt AC 70 ms 512680 KB
1