codeforces 19/10/26 div2E.Rock In Push

Posted thjkhdf12

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 19/10/26 div2E.Rock In Push相关的知识,希望对你有一定的参考价值。

技术图片
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 using namespace std;
 5 
 6 #define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
 7 #define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
 8 typedef long long int LL;
 9 
10 const int maxn = 2010;
11 const int mod = 1e9 + 7;
12 char a[maxn][maxn];
13 LL sumd[maxn][maxn];
14 LL sumr[maxn][maxn];
15 LL f[maxn][maxn][2];    //第三维0向右,1向下
16 int n, m;
17 
18 int main()
19 {
20     cin >> n >> m;
21     mfor(i, 1, n)
22     {
23         //scanf_s("%s", a[i] + 1, maxn);
24         scanf(" %s", a[i] + 1);
25     }
26     if (n == m && n == 1)
27     {
28         if (a[1][1] == .)
29         {
30             cout << 1;
31             return 0;
32         }
33     }
34     mrep(i, n, 1)
35     {
36         mrep(j, m, 1)
37         {
38             sumd[i][j] = sumd[i][j + 1] + (a[i][j] == R ? 1 : 0);
39             sumr[i][j] = sumr[i + 1][j] + (a[i][j] == R ? 1 : 0);
40         }
41     }
42     mfor(i, 1, n - 1)
43     {
44         if (!sumr[i][m]) f[i][m][0] = 1;
45     }
46     mfor(i, 1, m - 1)
47     {
48         if (!sumd[n][i]) f[n][i][1] = 1;
49     }
50     mrep(i, n - 1, 1)
51     {
52         mrep(j, m - 1, 1)
53         {
54             (f[i][j][0] += f[i + 1][j][1]) %= mod;
55             (f[i][j][1] += f[i][j + 1][0]) %= mod;
56             if (a[i + 1][j] == R) (f[i][j][0] += f[i + 1][j][0] - f[n - sumr[i + 1][j] + 1][j][1] + mod) %= mod;
57             else (f[i][j][0] += f[i + 1][j][0]) %= mod;
58             if (a[i][j + 1] == R) (f[i][j][1] += f[i][j + 1][1] - f[i][m - sumd[i][j + 1] + 1][0] + mod) %= mod;
59             else (f[i][j][1] += f[i][j + 1][1]) %= mod;
60         }
61     }
62     cout << (f[1][1][0] + f[1][1][1]) % mod;
63 }
View Code

 

以上是关于codeforces 19/10/26 div2E.Rock In Push的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces875C[拓扑排序] Codeforces Round #440 [DIV2E/DIV1C]

Codeforces #340 div2

Codeforces Round #326(Div2)

Codeforces Round #328(Div2)

Codeforces Round #327 (Div2)

Codeforces Round #329 div2