Submission #56016
ソースコード
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 | #include <bits/stdc++.h> using namespace std; #define long long long int cnt[22]; int n, m; int dp[1<<21]; int rui[100100][22]; // [begin, end) int get ( int begin, int end, int type ) { int ans = rui[end][type] - rui[begin][type]; // cout << ans << endl; return ans; } int dfs ( int bit ) { //cout << bit << endl; if ( ~dp[bit] ) return dp[bit]; if ( bit == (1<<m)-1 ) return 0; int already = 0; for ( int i = 0; i < m; i++ ) { if ( bit & ( 1 << i ) ) { already += cnt[i]; } } int rec = 0x3f3f3f3f; for ( int i = 0; i < m; i++ ) { if ( ! ( bit & ( 1 << i ) ) ) { rec = min ( rec, dfs ( bit|(1<<i) ) + ( cnt[i]-get(already, already+cnt[i], i) ) ); } } return dp[bit] = rec; } signed main ( ) { cin >> n >> m; for ( int i = 1; i <= n; i++ ) { int a; cin >> a; a--; cnt[a]++; for ( int j = 0; j < m; j++ ) { rui[i][j] = cnt[j]; } } memset (dp, -1, sizeof (dp)); cout << dfs ( 0 ) << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0595 - ぬいぐるみの整理 (Plush Toys) |
ユーザー名 | r1825 |
投稿日時 | 2019-11-01 17:20:11 |
言語 | C++14 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1152 Byte |
最大実行時間 | 148 ms |
最大メモリ使用量 | 17784 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 | 37 ms | 9052 KB |
1
|
||||
2017-yo-t4-in2.txt | AC | 29 ms | 9376 KB |
2
|
||||
2017-yo-t4-in3.txt | AC | 53 ms | 17580 KB |
3
|
||||
2017-yo-t4-in4.txt | AC | 74 ms | 9592 KB |
4
|
||||
2017-yo-t4-in5.txt | AC | 148 ms | 17784 KB |
5
|