#include <iostream.h>
const int Power[] ={1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049};
unsigned char best[4][10][59049];
bool bug[150][10];
int profile[10];
int d,m,n,k;
int x,y,p;
int tx, ty, tp;
int py, py1, py2, py3;
int pp,dd,kk;
int main()
{
cin>>d;
for ( dd=0; dd<d; dd++) {
cin>>n>>m>>k;
for ( x=0; x<n; x++)
for ( y=0; y<m; y++)
bug[x][y] = false;
for ( kk=0; kk<k; kk++) {
cin>>x>>y;
bug[x-1][y-1] = true;
}
int maxP = Power[m];
for ( y=0; y<m; y++) for (p=0; p<maxP; p++) best[0][y][p] = 0;
for ( x=1; x<n; x++) for ( y=0; y<m; y++) {
for ( pp=0,p=0,py=0,py1=0,py2=0; p<maxP; p++,pp++) {
if ( p==1 && y==m-1 && x==n-1 ) break;
if ( y==0 ) { if ( pp==3 ) pp=0; py = pp;}
else if ( y==1 )
{ if ( pp==3 ) {pp=0; py++;} py1 = pp; if ( py ==3 ) py=0;}
else if ( y==2 )
{ if ( pp==3 ) {pp=0; py1++;} py2 = pp; if ( py1==3 ) { py1=0; py++;} if ( py==3 ) py=0;}
else if ( y>2)
{if ( pp==Power[y-2] ) { pp=0; py2++;} if ( py2==3 ) { py2=0; py1++;} if ( py1==3 ) { py1=0; py++; } if (py==3 ) py=0;}
if ( py ) {
if ( y==0 ) { tx = x-1; ty = m-1;}
else { tx = x; ty= y-1; }
tp = p - Power[y];
best [x&3][y][p] = best[tx&3][ty][tp];
} else {
int temp1=0, temp2=0, temp3=0;
// can place 3*2 chip
if ( y>0 && x>1 && py1==0 && !bug[x][y] && !bug[x-1][y] && !bug[x-2][y] && !bug[x][y-1] && !bug[x-1][y-1] && !bug[x-2][y-1]) {
if ( y==1 ) { tx = x-1; ty = m-1; }
else { tx = x; ty = y-2; }
tp = p + Power[y+1] - Power[y-1];
temp1 = best[tx&3][ty][tp]+1;
}
// can place 2*3 chip
if ( y>1 && x>0 && py1==0 && py2==0 && !bug[x][y] && !bug[x-1][y] && !bug[x][y-1] && !bug[x-1][y-1] && !bug[x][y-2] && !bug[x-1][y-2]) {
if ( y==2 ) { tx = x-1; ty = m-1; }
else { tx = x; ty = y-3; }
tp = p + Power[y] + Power[y-1] + Power[y-2];
temp2 = best[tx&3][ty][tp]+1;
}
// place nothing
if ( y==0 ) { tx = x-1; ty = m-1; }
else { tx = x; ty = y-1; }
temp3 = best[tx&3][ty][p];
temp1 = (temp2>temp1) ? temp2 : temp1;
temp1 = (temp3>temp1) ? temp3 : temp1;
best[x&3][y][p] = temp1;
}
}
}
cout<<int(best[(n-1)&3][m-1][0])<<endl;
}
return 0;
}
分享到:
相关推荐
【压缩包子文件的文件名称列表】"1038--Bugs Integrated,Inc" 这个文件名可能是指参赛者编写的解决方案源代码文件,按照POJ的提交格式,它可能是以.C或.CPP为扩展名的C/C++代码,或者以.JAVA为扩展名的Java代码。...
在北大ACM题库中,压缩存储的DP题目,如“1038 Bugs Integrated Inc.”,以及最长公共子串(LCS)类问题,如“1080 Human Gene Functions”,都是动态规划的典型应用。这类问题通常需要构建状态转移方程,以最优子...
c. Provider account: Usertype: Provider Username: master Password: master Interface URL: http://www.yoursite.nul/xcart-directory/provider/ d. Root provider account: Usertype: Provider Username:...
String References integrated into disassembler. Fixed documented and undocumented crashes. Fixed some general bugs. 0.95 Phoenix -> Fixed some crashing bugs. Minor Core update. Greets ------ ...
5. **1038 Bugs Integrated, Inc.** - 从题目名推测,这道题可能与软件工程中的调试或错误处理有关。在实际开发中,有效地识别和修复bug是保证软件质量的关键步骤,涉及到调试技巧、日志分析等技能。 6. **1042 ...
首先,让我们关注到" Bugs Integrated, Inc.ppt",这可能是一个关于错误处理或调试策略的演示文稿。在实际开发中,理解和处理程序中的错误至关重要,尤其是在复杂的系统中。通过学习如何识别和解决“Bugs”,我们...
String References integrated into disassembler. Fixed documented and undocumented crashes. Fixed some general bugs. 0.95 Phoenix -> Fixed some crashing bugs. Minor Core update. Greets ------ ...
* IMPORTANT: Please edit file WPINC.INC to * activate WPREPORTER, WPSPELL, wPDF, TBX * and GraphicEx / PNGImage support! * Delphi 2009 and later as inbuilt PNGImage *********************************...
6. **Cocoa Compatibility**: Cocoa APIs are primarily written in C and Objective-C. Swift is explicitly designed to work seamlessly with most Cocoa APIs, allowing developers to leverage existing ...
However, Niels Jørgenssen has suggested a model of how written code is integrated into the project. Figure 4-1. Jørgenssen's model for change integration The “development release” is the ...
+ [enterprise] added property "Reports" - "Scripts" in server configuration - set the path for "uses" directive in report script + [enterprise] added property "Http" - "MaxSessions" in server ...
The BlitzMax package includes an 'integrated development environment' (IDE), which is used to enter your programs, and a debugger for tracking down bugs. Direct OpenGL support Thanks to the OpenGL ...
These concepts form the basis for any programming language, including Objective-C. For example, variables are used to store data, and control structures like loops and conditional statements help ...
EurekaLog is easy to use because it is fully integrated into the Delphi/CBuilder IDE. You just rebuild your application to add this new exception-logging capability. EurekaLog does not affect the ...
Updated simdesign.inc to add DXE2 ! Fixed bug in DirectNodeCount ! Fixed (removed) erratic un-normalisation ! removed erratic $ifdef in NativeXmlObjectStorage.pas Version 4.03 (13jul2012) * Core End...
The following bugs have been fixed in the ASP.NET MVC 2 Release Candidate release. The FileResult action result now supports non-US-ASCII characters in file names. Methods and properties of the ...
| i2c (Inter-Integrated Circuit) | Yes | Yes | Yes | | fb (FrameBuffer) | Under Development (tcort) | Under Development (tcort) | Yes | | EDID Reading (Extended Display Identification Data) | Yes | ...
**案例分析:Pku1038—Bugs Integrated, Inc.** 题目描述:给定一系列工人的工作效率和工作时间,需要分配工作任务,使得所有任务能在给定时间内完成。此类问题可以通过动态规划来解决,通过构建一个多维数组来存储...