acm总结
这个星期写了几道洛谷上的题,又重新熟悉了一下,dp和贪心就比如在p1002题中。
洛谷P1002过河卒
结合了bfs和dp问题。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int x1,y1,x2,y2;
#define Check(x,y)(x>=0&&x<=x1&&y>=0&&y<=y1)
int point[8][2]={{-2,-1},{-1,-2},{1,2},{2,1},{1,-2},{-2,1},{-1,2},{2,-1}};
int point1[2][2]={{-1,0},{0,-1}};
int main()
{
cin>>x1>>y1>>x2>>y2;
long long a[30][30];
memset(a,0,sizeof(a));
a[x2][y2]=-1;
a[x1][y1]=0;
for(int q=0;q<8;q++)
{
int x,y;
x=x2+point[q][0];
y=y2+point[q][1];
if(Check(x,y))
{
a[x][y]=-1;
}
}
a[0][0]=1;
for(int q=0;q<=x1;q++)
{
for(int w=0;w<=y1;w++)
{
if(a[q][w]!=-1)
{for(int e=0;e<2;e++)
{
int x=q+point1[e][0];
int y=w+point1[e][1];
if(Check(x,y)&&a[x][y]!=-1)
{
a[q][w]=a[q][w]+a[x][y];
}
}}
}
}
cout<<a[x1][y1];
return 0;
}
加油,接着努力!