您的位置:首页 > 其它

hihocoder 1191 小W与网格

2015-07-27 00:24 274 查看
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 105
#define MOD 1000000007
int n,m,_,i,j,a,b,dp[MAXN][MAXN],vis[MAXN][MAXN];
int dfs(int y,int x)
{
    //if(x == 0 || y == 0)return 1;
    if(dp[y][x])return dp[y][x];
    int curx = 0,cury = 0;
    if(x + b > m || x + b < 1)
    {
        curx = !vis[y][x];
        vis[y][x] = true;
    }
    else curx = dfs(y,x + b);

    if(y + a > n || y + a < 1)
    {
        cury = !vis[y][x];
        vis[y][x] = true;
    }
    else cury = dfs(y + a,x);

    return dp[y][x] = (curx + cury) % MOD;
}
int solve()
{
    if(m == 1 && n == 1)return 1;
    memset(dp,0,sizeof(dp));
    memset(vis,0,sizeof(vis));
    a = -1 , b = -1;
    int ans = dfs(i,j) % MOD;
    //cout << ans << endl;
    memset(dp,0,sizeof(dp));
    a = 1 , b = 1;
    ans = (ans + dfs(i,j)) % MOD;
    //cout << ans << endl;
    a = -1,b = 1;
    memset(dp,0,sizeof(dp));
    ans = (ans + dfs(i,j)) % MOD;
    //cout << ans << endl;
    a = 1,b = -1;
    memset(dp,0,sizeof(dp));
    ans = (ans + dfs(i,j)) % MOD;
    return ans;
}
int main()
{
    while(cin >> n >> m >> i >> j)
    {
        int ans = solve();
        cout << ans << endl;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: