CEOI 2002, POJ 1038 Bugs Integrated, Inc. 状态压缩 DP
来源:互联网 发布:九世犹可以复仇乎 编辑:程序博客网 时间:2024/05/31 06:23
Bugs Integrated, Inc.
Time Limit: 15000MS Memory Limit: 30000KTotal Submissions: 9052 Accepted: 3458Case Time Limit: 5000MS
Description
Bugs Integrated, Inc. is a major manufacturer of advanced memory chips. They are launching production of a new six terabyte Q-RAM chip. Each chip consists of six unit squares arranged in a form of a 2*3 rectangle. The way Q-RAM chips are made is such that one takes a rectangular plate of silicon divided into N*M unit squares. Then all squares are tested carefully and the bad ones are marked with a black marker.
Finally, the plate of silicon is cut into memory chips. Each chip consists of 2*3 (or 3*2) unit squares. Of course, no chip can contain any bad (marked) squares. It might not be possible to cut the plate so that every good unit square is a part of some memory chip. The corporation wants to waste as little good squares as possible. Therefore they would like to know how to cut the plate to make the maximum number of chips possible.
Task
You are given the dimensions of several silicon plates and a list of all bad unit squares for each plate. Your task is to write a program that computes for each plate the maximum number of chips that can be cut out of the plate.
Finally, the plate of silicon is cut into memory chips. Each chip consists of 2*3 (or 3*2) unit squares. Of course, no chip can contain any bad (marked) squares. It might not be possible to cut the plate so that every good unit square is a part of some memory chip. The corporation wants to waste as little good squares as possible. Therefore they would like to know how to cut the plate to make the maximum number of chips possible.
Task
You are given the dimensions of several silicon plates and a list of all bad unit squares for each plate. Your task is to write a program that computes for each plate the maximum number of chips that can be cut out of the plate.
Input
The first line of the input file consists of a single integer D (1 <= D <= 5), denoting the number of silicon plates. D blocks follow, each describing one silicon plate. The first line of each block contains three integers N (1 <= N <= 150), M (1 <= M <= 10), K (0 <= K <= MN) separated by single spaces. N is the length of the plate, M is its height and K is the number of bad squares in the plate. The following K lines contain a list of bad squares. Each line consists of two integers x and y (1 <= x <= N, 1 <= y <= M) ?coordinates of one bad square (the upper left square has coordinates [1, 1], the bottom right is [N,M]).
Output
For each plate in the input file output a single line containing the maximum number of memory chips that can be cut out of the plate.
Sample Input
26 6 51 44 62 23 66 46 5 43 36 16 26 4
Sample Output
34
Source
CEOI 2002
有点点小虐心。
#include <iostream>#include <cstring>#include <fstream>using namespace std;const int ternarys[12] = { 0, 1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049 };int DP[2][59049];int bit_map[155][15];int pre_line[15];int now_line[15];int N, M, K;int transform_to_decimal( int* arr ){ int res = 0; for( int m = 1; m <= M; ++m ) res += arr[m] * ternarys[m]; return res;}void transform_to_ternary( int val, int* arr ){ for( int m = 1; m <= M; ++m ){ arr[m] = val % 3; val /= 3; }}void dfs_search( int n, int m, int last, int state ){ DP[n % 2][state] = max( DP[n % 2][state], last ); if( m >= M ) return; if( !pre_line[m] && !pre_line[m + 1] && !now_line[m] && !now_line[m + 1] ){ now_line[m] = now_line[m + 1] = 2; int _state = transform_to_decimal( now_line ); dfs_search( n, m + 2, last + 1, _state ); now_line[m] = now_line[m + 1] = 0; } if( m < M - 1 && !now_line[m] && !now_line[m + 1] && !now_line[m + 2] ){ now_line[m] = now_line[m + 1] = now_line[m + 2] = 2; int _state = transform_to_decimal( now_line ); dfs_search( n, m + 3, last + 1, _state ); now_line[m] = now_line[m + 1] = now_line[m + 2] = 0; } dfs_search( n, m + 1, last, state );}int main(){ int cases; cin >> cases; while( cases-- ){ cin >> N >> M >> K; for( int i = 0; i < ternarys[M + 1]; ++i ) DP[1][i] = -1; memset( bit_map, 0, sizeof( bit_map ) ); for( int k = 0; k < K; ++k ){ int n, m; cin >> n >> m; bit_map[n][m] = 1; } for( int i = 1; i <= M; ++i ) pre_line[i] = bit_map[1][i] + 1; int state = transform_to_decimal( pre_line ); DP[1][state] = 0; for( int n = 2; n <= N; ++n ){ for( int _state = 0; _state < ternarys[M + 1]; ++_state ) DP[n % 2][_state] = -1; for( int _state = 0; _state < ternarys[M + 1]; ++_state ){ if( DP[( n + 1 ) % 2][_state] == -1 ) continue; transform_to_ternary( _state, pre_line ); for( int m = 1; m <= M; ++m ){ if( bit_map[n][m] ) now_line[m] = 2; else now_line[m] = max( pre_line[m] - 1, 0 ); } int now_state = transform_to_decimal( now_line ); dfs_search( n, 1, DP[( n + 1 ) % 2][_state], now_state ); } } int res = 0; for( int _state = 0; _state < ternarys[M + 1]; ++_state ) res = max( res, DP[N % 2][_state] ); cout << res << endl; } return 0;}
0 0
- CEOI 2002, POJ 1038 Bugs Integrated, Inc. 状态压缩 DP
- [状态压缩 dp] [CEOI 2002] Bugs Integrated, Inc.
- poj 1038 - Bugs Integrated, Inc.(状态压缩dp)
- 状态压缩dp POJ 1038 Bugs Integrated, Inc.
- POJ 1038 Bugs Integrated, Inc. 状态压缩DP
- poj 1038 Bugs Integrated, Inc. 状态压缩dp
- 1038 Bugs Integrated, Inc.//状态压缩DP
- POJ--1038--Bugs Integrated, Inc.--状态DP
- 【DP,状态压缩】PKU-1038-Bugs Integrated, Inc.
- poj 1038 Bugs Integrated, Inc.(动态规划状态压缩)
- poj 1038 Bugs Integrated, Inc. __dp状态压缩
- poj 1038 Bugs Integrated, Inc. __dp状态压缩
- POJ 1038 Bugs Integrated, Inc. 三进制压缩DP
- POJ 1038 Bugs Integrated, Inc. 状态压缩dp+3进制枚举
- poj 1038 Bugs Integrated, Inc. 状态DP+四进制+DFS
- POJ 1038 - Bugs Integrated, Inc. 三进制状态DP
- CEOI 2002 Bugs公司 - 状态压缩DP
- poj 1038 Bugs Integrated, Inc. 状压dp
- 设计模式——外观模式
- 只要简单7步就能破解魔方的图文教程!怎样还原魔方?
- 第十三周项目六 体验文件操作(实战)
- Fragment使用时遇到的二个问题
- ORA-01578 ORACLE data block corrupted
- CEOI 2002, POJ 1038 Bugs Integrated, Inc. 状态压缩 DP
- 第13周 项目5-2 统计指定字母的个数
- 黑马程序员_JAVA_反射
- 汉诺塔II
- C实现插入排序
- 增加重做日志组大小和增加日志组成员
- Thinkphp常用系统变量指导
- base64:URL背景图片与web页面性能优化
- cocos2dx-lua 之 ProgressTimer 条形进度条 简单血条的实现