比如说样例中的马的位置是在(3,2)所以漏判(禅州2,0)这个点是不可达的。由于卒只能向下和向右走,(2,0)之下的所有的点都是不可达的。所以你的答案会错。
int main()
{
int n,m,x,y,i,j,t,h,l
long long a[100][100],b[100][100]
scanf("%d%d%d%d",&n,&m,&x,&y)
for(i=0i<=ni++)
{
for(j=0j<=mj++)
{
if((i==x&&j==y)||(i==x-2&&j==y-1)||(i==x-2&&j==y+1)||(i==x-1&&j==y-2)||(i==x-1&&j==y+2)||(i==x+1&&j==y-2)||(i==x+1&&j==y+2)||(i==x+2&&j==y-1)||(i==x+2&&j==y+1))
{
b[i][j]=0
}
else
{
b[i][j]=1
}
}
}
for(h=0h<=nh++)
{
for(l=0l<=ml++)
{
if(b[h][l]==1)
{
if(h==0 &&l==0)
a[h][l]=1
else if(h == 0)
a[h][l] = a[h][l-1]
else if(l == 0)
a[h][l] = a[h-1][l]
else
a[h][l]=a[h][l-1]+a[h-1][l]
}
else
a[h][l]=0
}
}
printf("%d",a[n][m])
return 0
}
#include<iostream>using namespace std
int const Max = 16
int dir[][2] = { { 1, 0 }, { 0, 1 } }
int dp[Max][Max] = { 0 }
int k = 0 //计数器
struct Point {
int x, y
}
Point b, horse
bool onboard(int x, int y) {
return x>=0 && x<Max && y>=0 && y<Max
}
void on(int x, int y) //将马附近的坐标记作1
{
if(onboard(x,y)) dp[x][y] = 1
码宴 if(onboard(x-2,y-1)) dp[x - 2][y - 1] = 1
if(onboard(x-2,y+1)) dp[x - 2][y + 1] = 1
if(onboard(x+2,y-1)) dp[x + 2][y - 1] = 1
if(onboard(x+2,y+1)) dp[x + 2][y + 1] = 1
if(onboard(x-1,y-2)) dp[x - 1][y - 2] = 1
if(onboard(x-1,y+2)) dp[x - 1][y + 2] = 1
if(onboard(x+1,y-2)) dp[x + 1][y - 2] = 1
if(onboard(x+1,y+2)) dp[x + 1][y + 2] = 1
}
void dfs(int x, int y) {
if(x > b.x || y > b.y) return // 如果提速,加上这行
if (x == b.x && y == b.y) {
++k
return
}
for (int i = 0 i < 2 i++) {
int IX = x + dir[i][0]
int IY = y + dir[i][1]
if (onboard(IX, IY)) {
if (dp[IX][IY] == 0) {
dfs(IX, IY)
迟行银 }
}
}
}
int main() {
cin >> b.x >> b.y >> horse.x >> horse.y
on(horse.x, horse.y)
dfs(0, 0)
cout << k
} #include<iostream>
using namespace std
int const Max = 16
int const dir[][2] = { { 1, 0 }, { 0, 1 } }
int dp[Max][Max] = { 0 }
int k = 0 //计数器
struct Point {
int x, y
}
Point b, horse
bool onboard(Point p) {
return p.x>=0 && p.x<Max && p.y>=0 && p.y<Max
}
void on(Point p) //将马附近的坐标记作1
{
int x = p.x, y = 带脊p.y
if(onboard({x,y})) dp[x][y] = 1
if(onboard({x-2,y-1})) dp[x - 2][y - 1] = 1
if(onboard({x-2,y+1})) dp[x - 2][y + 1] = 1
if(onboard({x+2,y-1})) dp[x + 2][y - 1] = 1
if(onboard({x+2,y+1})) dp[x + 2][y + 1] = 1
if(onboard({x-1,y-2})) dp[x - 1][y - 2] = 1
if(onboard({x-1,y+2})) dp[x - 1][y + 2] = 1
if(onboard({x+1,y-2})) dp[x + 1][y - 2] = 1
if(onboard({x+1,y+2})) dp[x + 1][y + 2] = 1
}
void dfs(Point current) {
int x = current.x, y = current.y
if(x > b.x || y > b.y) return // 如果提速,加上这行
if (x == b.x && y == b.y) {
++k
return
}
for (int i = 0 i < 2 i++) {
int IX = x + dir[i][0]
int IY = y + dir[i][1]
if (onboard({IX, IY})) {
if (dp[IX][IY] == 0) {
dfs({IX, IY})
}
}
}
}
int main() {
cin >> b.x >> b.y >> horse.x >> horse.y
on(horse)
dfs({0, 0})
cout << k
}
program E1_1{knight}const
dx:array[1..8] of integer=(-2,-1,1,2,2,1,-1,-2)
dy:array[1..8] of integer=(1,2,2,1,-1,-2,-2,-1)
这个就是传说中的增量矩阵。其实也没那么神秘,就是一张表,有8种变化陆清状态,每种状态对应了一个delta
x和y,比如第一种变化,x坐标减誉配小2,y坐标加1。表示在棋盘上的8种行走方式。
var
n,m,x,y,i,j: byte
g:array[0..20,0..20] of 0..1
c:longint
infile,outfile:text
//这早虚前边是关键步骤
procedure sol(x,y:integer)
var i:integer
begin
if (x=n) and (y=m) then c:=c+1(当前x,y坐标都为目标坐标,那么总路径c +1,c为统计的路径条数) else
begin//深搜,只有2个法则,向上y+1,向左x+1。并且判断有没有出界。
if (y<m) and (g[x,y+1]=0) then sol(x,y+1)
if (x<n) and (g[x+1,y]=0) then sol(x+1,y)
end
end
begin
assign(infile,'knight.in')
assign(outfile,'knight.out')
reset(infile)
readln(infile,n,m,x,y)
close(infile)
g[x,y] := 1
for i:=1 to 8 do
if (x+dx[i]>=0) and (x+dx[i]<=n) and (y+dy[i]>=0) and (y+dy[i]<=m) then
g[x+dx[i],y+dy[i]]:=1//给地图赋值,0为可走,1为被马控制,如g[1,1]=1说明坐标(1,1)点被控制了。
sol(0,0)//从坐标(0,0)开始走。
rewrite(outfile)
writeln(outfile,c)
close(outfile)
end.
/----------------------------------------------------/
type arr=array [1..4] of integer
var i,result,n,len:integer
d:arr
r:array [1..3,1..4] of integer
procedure print //打答案用的,r[i,1],r[i,3]为运算数字,r[i,2]为运算符,r[i,4]为答案
var i,j:integer
begin
assign(output,'point.out')rewrite(output)
for i:=1 to 3 do
begin
for j:=1 to 3 do
if j<>2 then write(r[i,j])
else case r[i,j] of
1:write('+')
2:write('-')
3:write('*')
4:write('/')
end
writeln('=',r[i,4])
end
close(output)
end
procedure try(k:integervar d:arr) //枚举,d数组暂存结果
var a,b,i,j,l,t:integer
e:arr
begin
if k=1 then
if d[1]=24 then begin printhalt end
else
elsebegin
for i:=1 to k-1 do
for j:=i+1 to k do
begin
a:=d[i]b:=d[j] //枚举要用的两个数
if a<b then begin t:=aa:=bb:=t end
t:=0
for l:=1 to k do if (l<>i) and (l<>j) then begin t:=t+1e[t]:=d[l] end //将剩下的数放好
r[5-k,1]:=a
r[5-k,3]:=b
r[5-k,4]:=-1
for l:=1 to 4 do //枚举运算符
begin
case l of
1:r[5-k,4]:=a+b
2:r[5-k,4]:=a-b
3:r[5-k,4]:=a*b
4:if b<>0 then if a mod b=0 then r[5-k,4]:=a div b
end
r[5-k,2]:=l
if r[5-k,4]<>-1 then
begin
e[t+1]:=r[5-k,4]
try(k-1,e)
end
end
end
end
end
begin
assign(input,'point.in')reset(input)
for i:=1 to 4 do read(d[i])
close(input)
try(4,d)
assign(output,'point.out')rewrite(output)
writeln('No answer!')
close(output)
end.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)