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; } }
相关文章推荐
- vim常用命令总结
- POJ 3071 Football 【概率DP】
- Mac OS X开机启动Path had bad permissions错误解决方案
- 数据结构(二):线性表的使用原则以及链表的应用-稀疏矩阵的三元组表示
- sort
- window中的常见方法
- 超过130个你需要了解的vim命令
- 大型网站技术架构
- 插入排序(java)
- 病毒侵袭
- spring+spring-mvc+mybatis配置
- 在photoshop cs5中保存图像文件的方法
- 在photoshop cs5中保存图像文件的方法
- JavaScript权威指南_140_第15章_脚本化文档_15.9-HTML表单-表单和元素的属性
- Android开源项目整理:个性化空间View篇(看遍论坛千万篇,不看此篇也枉然)
- cl: cannot open file 'kernel32.lib'
- Linux strace命令
- 读书笔记MoreEffectiveC++(11)
- Java中内存泄露和内存溢出的区别
- OC面向对象