AT_joi2007yo_f 通学経路 题解
题目大意:
有一个网格,太郎君可以向上走或向右走,但是有些点是不能走的,求太郎君从
思路分析:
一眼朴素 dp。
设太郎君走到
-
如果
(x,y) 不能走,f_{x,y}=0 。 -
如果
(x,y) 可以走,f_{x,y}=f_{x-1,y}+f_{x,y-1} 。
然后按上述思路操作即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int a,b,n,x,y,f[41][41];
bool st[41][41];
int main()
{
cin>>a>>b>>n;
for(int i=0;i<n;i++)
{
cin>>x>>y;
st[x][y]=1;
}
f[0][1]=1;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
if(!st[i][j]) f[i][j]=f[i-1][j]+f[i][j-1];
cout<<f[a][b]<<"\n";
return 0;
}