Submission #00053
ソースコード
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 52 53 54 55 56 57 | #include <bits/stdc++.h> using namespace std; int n, m; int mas[21][100010] = {}; int dp[2000000] = {}; int num[21] = {}; int solve( int now, int bit){ if (now == n){ return 0; } if (dp[bit] != -1){ return dp[bit]; } int ans = INT_MAX; for ( int i = 0;i < m;i++){ if ((bit & (1 << i)) == 0){ ans = min(ans, solve(now+num[i], bit | (1 << i)) + (mas[i][now+num[i]] - mas[i][now])); } } return dp[bit] = ans; } int main(){ cin >> n >> m; for ( int i = 0;i < m;i++){ for ( int j = 1;j <= n;j++){ mas[i][j] = 1; } } for ( int i = 0;i < n;i++){ int tmp; cin >> tmp; tmp--; mas[tmp][i+1] = 0; num[tmp]++; } for ( int i = 0;i < m;i++){ for ( int j = 0;j <= n+2;j++){ mas[i][j+1] += mas[i][j]; } } memset (dp, -1, sizeof (dp)); cout << solve(0, 0) << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0004 - ぬいぐるみの整理 (Plush Toys) |
ユーザー名 | ei1719 |
投稿日時 | 2018-11-21 17:43:47 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 918 Byte |
最大実行時間 | 101 ms |
最大メモリ使用量 | 16088 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | set1 | 20 / 20 | *t4*1.txt |
2 | set2 | 20 / 20 | *t4*2.txt |
3 | set3 | 20 / 20 | *t4*3.txt |
4 | set4 | 20 / 20 | *t4*4.txt |
5 | set5 | 20 / 20 | *t4*5.txt |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
2017-yo-t4-in1.txt | AC | 28 ms | 10844 KB |
1
|
||||
2017-yo-t4-in2.txt | AC | 25 ms | 12872 KB |
2
|
||||
2017-yo-t4-in3.txt | AC | 37 ms | 12720 KB |
3
|
||||
2017-yo-t4-in4.txt | AC | 54 ms | 14868 KB |
4
|
||||
2017-yo-t4-in5.txt | AC | 101 ms | 16088 KB |
5
|