求大神把c++代码转换成pascal,在线等,急啊
boolTestFirstLine(intnStatus)//testthefirstline{inti=0;while(i<g_Width){if(nStatus&(0...
bool TestFirstLine(int nStatus) //test the first line
{
int i = 0;
while( i < g_Width)
{
if(nStatus & (0x1 << i))
{
if( i == g_Width -1 || (nStatus & (0x1 << (i+1))) == 0)
{
return false;
}
i += 2;
}
else
{ i++; }
}
return true; }
bool CompatablityTest(int nStatusA, int nStatusB) // test if status (i, nStatusA) and (i-1, nStatusB) is compatable.
{ int i = 0;
while( i < g_Width)
{ if( (nStatusA & (0x1 << i)) == 0)
{ if((nStatusB & (0x1 << i)) == 0)
{ return false; }
i++; }
else
{ if((nStatusB & (0x1 << i)) == 0 )
{ i++;
}
else if( (i == g_Width - 1) || ! ( (nStatusA & (0x1 << (i+1))) && (nStatusB & (0x1 << (i + 1)))) )
{
return false;
}
else
{
i += 2;
}
}
}
return true;
}
int main()
{
int i,j;
int k;
while(scanf("%d%d", &g_Height, &g_Width) != EOF )
{
if(g_Width == 0 && g_Height == 0)
{
break;
}
if(g_Width > g_Height)
{
swap(g_Width, g_Height);
}
int nAllStatus = 2 << (g_Width-1);
memset(DP, 0, sizeof(DP));
for( j = 0; j < nAllStatus; j++)
{
if(TestFirstLine(j))
{
DP[0][j] = 1;
}
}
for( i = 1; i < g_Height; i++)
{
for( j = 0; j < nAllStatus; j++)// iterate all status for line i
{
for( k = 0; k < nAllStatus; k++) // iterate all status for line i-1
{
if(CompatablityTest(j, k))
{
DP[i][j] += DP[i-1][k];
}
}
}
}
printf("%lld\n", DP[g_Height-1][nAllStatus - 1]);
}
return 0;
} 展开
{
int i = 0;
while( i < g_Width)
{
if(nStatus & (0x1 << i))
{
if( i == g_Width -1 || (nStatus & (0x1 << (i+1))) == 0)
{
return false;
}
i += 2;
}
else
{ i++; }
}
return true; }
bool CompatablityTest(int nStatusA, int nStatusB) // test if status (i, nStatusA) and (i-1, nStatusB) is compatable.
{ int i = 0;
while( i < g_Width)
{ if( (nStatusA & (0x1 << i)) == 0)
{ if((nStatusB & (0x1 << i)) == 0)
{ return false; }
i++; }
else
{ if((nStatusB & (0x1 << i)) == 0 )
{ i++;
}
else if( (i == g_Width - 1) || ! ( (nStatusA & (0x1 << (i+1))) && (nStatusB & (0x1 << (i + 1)))) )
{
return false;
}
else
{
i += 2;
}
}
}
return true;
}
int main()
{
int i,j;
int k;
while(scanf("%d%d", &g_Height, &g_Width) != EOF )
{
if(g_Width == 0 && g_Height == 0)
{
break;
}
if(g_Width > g_Height)
{
swap(g_Width, g_Height);
}
int nAllStatus = 2 << (g_Width-1);
memset(DP, 0, sizeof(DP));
for( j = 0; j < nAllStatus; j++)
{
if(TestFirstLine(j))
{
DP[0][j] = 1;
}
}
for( i = 1; i < g_Height; i++)
{
for( j = 0; j < nAllStatus; j++)// iterate all status for line i
{
for( k = 0; k < nAllStatus; k++) // iterate all status for line i-1
{
if(CompatablityTest(j, k))
{
DP[i][j] += DP[i-1][k];
}
}
}
}
printf("%lld\n", DP[g_Height-1][nAllStatus - 1]);
}
return 0;
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏100(财富值+成长值)
1个回答
展开全部
var i,j,k,swap,nAllStatus,g_Height,g_Width:integer;
DP:array[1..1000,1..1000]of integer;
procedure swap1(g_Height,g_Width:integer);
var tmp:integer;
begin
tmp:=g_Height;
g_Height:=g_Width;
g_Width:=tmp;
end;
function TestFirstLine(nStatus:integer):boolean;
var i:integer;
begin
i:=0;
while i<g_Width do
begin
if (nStatus and ($1 << i)) = 0 then // =0 还是其他我不清楚
begin
if (i=g_Width-1) or ((nStatus and ($1 << (i+1))) = 0) then exit(false);
inc(i,2);
end
else inc(i);
end;
exit(true);
end;
function CompatablityTest(nStatusA,nStatusB:integer):boolean; // test if status (i,nStatusA) and (i-1, nStatusB) is compatable.
var i:integer;
begin
i:=0;
while not eof do
begin
read(g_Height,g_Width);
if (nStatusA and ($1 << i)) = 0 then
begin
if(nStatusB and ($1 << i)) = 0 then exit(false);
inc(i);
end
else
begin
if (nStatusB and ($1 << i)) = 0 then inc(i)
else if (i = g_Width - 1) or not (((nStatusA and ($1 << (i+1)))=0) and ((nStatusB and ($1 << (i + 1)))=0)) then exit(false) // =0 不确定
else inc(i,2);
end;
end;
exit(true);
end;
begin //main
while true do
begin
if (g_Width = 0) and (g_Height = 0) then break;
if g_Width > g_Height then swap1(g_Width, g_Height);
nAllStatus:=2<<g_Width-1;
fillchar(DP,sizeof(DP),0);
for i:=1 to nAllStatus do
begin
if TestFirstLine(j) then
begin
DP[1,j]:=1;
end;
end;
for i:=1 to g_Height do
begin
for j:=1 to nAllStatus do// iterate all status for line i
begin
for k:=1 to nAllStatus do // iterate all status for line i-1
begin
if CompatablityTest(j, k) then DP[i,j]:=DP[i,j]+DP[i-1,k];
end;
end;
end;
writeln(DP[g_Height-1,nAllStatus-1]);
end;
readln;
end.
//还有些问题,欢迎提问。
DP:array[1..1000,1..1000]of integer;
procedure swap1(g_Height,g_Width:integer);
var tmp:integer;
begin
tmp:=g_Height;
g_Height:=g_Width;
g_Width:=tmp;
end;
function TestFirstLine(nStatus:integer):boolean;
var i:integer;
begin
i:=0;
while i<g_Width do
begin
if (nStatus and ($1 << i)) = 0 then // =0 还是其他我不清楚
begin
if (i=g_Width-1) or ((nStatus and ($1 << (i+1))) = 0) then exit(false);
inc(i,2);
end
else inc(i);
end;
exit(true);
end;
function CompatablityTest(nStatusA,nStatusB:integer):boolean; // test if status (i,nStatusA) and (i-1, nStatusB) is compatable.
var i:integer;
begin
i:=0;
while not eof do
begin
read(g_Height,g_Width);
if (nStatusA and ($1 << i)) = 0 then
begin
if(nStatusB and ($1 << i)) = 0 then exit(false);
inc(i);
end
else
begin
if (nStatusB and ($1 << i)) = 0 then inc(i)
else if (i = g_Width - 1) or not (((nStatusA and ($1 << (i+1)))=0) and ((nStatusB and ($1 << (i + 1)))=0)) then exit(false) // =0 不确定
else inc(i,2);
end;
end;
exit(true);
end;
begin //main
while true do
begin
if (g_Width = 0) and (g_Height = 0) then break;
if g_Width > g_Height then swap1(g_Width, g_Height);
nAllStatus:=2<<g_Width-1;
fillchar(DP,sizeof(DP),0);
for i:=1 to nAllStatus do
begin
if TestFirstLine(j) then
begin
DP[1,j]:=1;
end;
end;
for i:=1 to g_Height do
begin
for j:=1 to nAllStatus do// iterate all status for line i
begin
for k:=1 to nAllStatus do // iterate all status for line i-1
begin
if CompatablityTest(j, k) then DP[i,j]:=DP[i,j]+DP[i-1,k];
end;
end;
end;
writeln(DP[g_Height-1,nAllStatus-1]);
end;
readln;
end.
//还有些问题,欢迎提问。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询