Submission #44459
ソースコード
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 | #include <bits/stdc++.h> using namespace std; int n, m; int rui[20][100010] = {}; int dp[2000000]; int cnt[20] = {}; int dfs( int x, int bit){ if (x == 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,dfs(x+cnt[i],bit | (1 << i)) + rui[i][x+cnt[i]]-rui[i][x]); } } return dp[bit] = ans; } int main(){ cin >> n >> m; int a[100010]; for ( int i = 0;i < m;i++) for ( int j = 0;j <= n;j++) rui[i][j] = 1; for ( int i = 0;i < n;i++){ cin >> a[i]; rui[a[i]-1][i+1] = 0; cnt[a[i]-1]++; } for ( int i = 0;i < m;i++) for ( int j = 1;j <= n+1;j++) rui[i][j] += rui[i][j-1]; memset (dp,-1, sizeof (dp)); cout << dfs(0,0) << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0595 - ぬいぐるみの整理 (Plush Toys) |
ユーザー名 | ei1719 |
投稿日時 | 2018-10-29 22:38:01 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 833 Byte |
最大実行時間 | 135 ms |
最大メモリ使用量 | 16944 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 | 62 ms | 10844 KB |
1
|
||||
2017-yo-t4-in2.txt | AC | 22 ms | 12992 KB |
2
|
||||
2017-yo-t4-in3.txt | AC | 78 ms | 13464 KB |
3
|
||||
2017-yo-t4-in4.txt | AC | 55 ms | 15104 KB |
4
|
||||
2017-yo-t4-in5.txt | AC | 135 ms | 16944 KB |
5
|