牛客小白月赛19B

https://ac.nowcoder.com/acm/contest/2272/B

题意::求从左下角到右上角的走法总数;

思路:;直接dp;因为题意给出 只能向上走或这向右走,因此转移方程  dp[i][j]=dp[i][j-1]+dp[i+1][j];

初始化见代码

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 #define ll long long
 5 using namespace std;
 6 const int maxn=3005;
 7 const int  MOD=2333;
 8 
 9 template<class T>inline void read(T &res)
10 {
11 char c;T flag=1;
12 while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
13 while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
14 }
15 int a[maxn][maxn];
16 int dp[maxn][maxn];
17 int main()
18 {
19     int n,m;
20     read(n);
21     read(m);
22     for(int i=1;i<=n;i++){
23         for(int j=1;j<=m;j++){
24             read(a[i][j]);
25         }
26     }
27     for(int i=1;i<=m;i++){
28         dp[n+1][i]=0;
29     }
30     dp[n][0]=1;
31     for(int i=n;i>=1;i--){
32         for(int j=1;j<=m;j++){
33             if(!a[i][j]){
34                 dp[i][j]=(dp[i][j-1]+dp[i+1][j])%MOD;
35             }
36             else{
37                 dp[i][j]=0;
38             }
39         }
40     }
41     cout<<dp[1][m]<<endl;
42     return 0;
43 }
纵使单枪匹马,也要勇闯天涯
原文地址:https://www.cnblogs.com/sj-gank/p/11959157.html