【弱省胡策】Round #0 【Flower Dance】

来源:互联网 发布:linux mysql 远程访问 编辑:程序博客网 时间:2024/06/04 23:36

求有坏点的网格图的从左上角到右下角不相交的两条路径的个数。

先求出所有方案减去相交的方案。

对于相交方案,将最后一个交点后两人的路径互换。


#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define Rep(i, x, y) for (int i = x; i <= y; i ++)#define Dwn(i, x, y) for (int i = x; i >= y; i --)#define RepE(i, x) for(int i = pos[x]; i; i = g[i].nex)using namespace std;typedef long long LL;const int N = 2005, mod = 1000000007;int n, m, f[N][N];char s[N][N];LL Calc(int x, int y, int x2, int y2) {if (s[x][y] == '1') return 0;memset(f, 0, sizeof(f));f[x][y] = 1;Rep(i, x, x2) {Rep(j, y, y2) if ((i != x || j != y) && s[i][j] != '1') {f[i][j] = (f[i - 1][j] + f[i][j - 1]) % mod;}}return f[x2][y2];}int main(){scanf ("%d%d", &n, &m);Rep(i, 1, n) {scanf ("%s", s[i] + 1);}LL ans = Calc(1, 2, n - 1, m) * Calc(2, 1, n, m - 1) % mod - Calc(1, 2, n, m - 1) * Calc(2, 1, n - 1, m) % mod + mod;cout << ans % mod << endl;    return 0;}


0 0