示例1
輸入
3 3 0 1 0 0 0 0 0 0 0
輸出
3
備註:
對於30%的數據,n,m≤100 對於100%的數據,n,m≤3,000 數據規模較大,請使用較快的輸入方式,以下爲快速讀入模板
template<class T>inline void read(T &res)//快速讀入模板
{
char c;
T flag=1;
while((c=getchar())<'0'||c>'9')
if(c=='-')
flag=-1;
res=c-'0';
while((c=getchar())>='0'&&c<='9')
res=res*10+c-'0';
res*=flag;
}
scanf("%d",&x) -> read(x)
cin>>x -> read(x)
(調用方式:read(要讀入的數))
題意:中文題,不過多敘述題意。
思路:這道題的話,題裏讓從左下角->右上角,是非常典型的DP,然後我們推一下遞推方程:
,表示當前點是由左側和下側得來的,有了遞推方程,再做這道題就很輕鬆了。
AC代碼:
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
const int maxx=110;
const int mod=2333;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
using namespace std;
template<class T>inline void read(T &res)//快速讀入模板
{
char c;
T flag=1;
while((c=getchar())<'0'||c>'9')
if(c=='-')
flag=-1;
res=c-'0';
while((c=getchar())>='0'&&c<='9')
res=res*10+c-'0';
res*=flag;
}
int dp[maxx][maxx];
int a[maxx][maxx];
int main()
{
int m,n;
read(m),read(n);
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
read(a[i][j]);
}
}
memset(dp,0,sizeof(dp));
dp[m][1]=1;
for(int i=m; i>=1; i--)
{
for(int j=1; j<=n; j++)
{
if(a[i][j]==1)
continue;
if(i!=n || j!=1)
dp[i][j]=(dp[i+1][j]+dp[i][j-1])%mod;
}
}
printf("%d\n",dp[1][n]);
return 0;
}