1. #include <iostream>
  2. #include <string>
  3. #define LL long long
  4. #define MAXN 100
  5. using namespace std;
  6.  
  7. int dis[][] = {,,,};
  8.  
  9. int _m[MAXN][MAXN];
  10. LL dp[MAXN][MAXN];
  11. struct node
  12. {
  13. int x;
  14. int y;
  15. };
  16. int n;
  17. LL dfs(node _node);
  18. //bool mark[MAXN][MAXN];
  19. int main()
  20. {
  21. //freopen("acm.acm","r",stdin);
  22.  
  23. int i;
  24. int j;
  25. string s;
  26. while(cin>>n)
  27. {
  28. getchar();
  29. if(n == -)
  30. {
  31. break;
  32. }
  33. memset(dp,,sizeof(dp));
  34. for(i = ; i < n; ++ i)
  35. {
  36. getline(cin,s);
  37. for(j = ; j < n; ++ j)
  38. {
  39. //cin>>_m[i][j];
  40. _m[i][j] = s[j]-'';
  41. }
  42. }
  43.  
  44. node b;
  45. b.x = ;
  46. b.y = ;
  47. cout<<dfs(b)<<endl;
  48. }
  49. }
  50.  
  51. LL dfs(node _node)
  52. {
  53. if(_node.x == n- && _node.y == n-)
  54. {
  55. return ;
  56. }
  57. if(_m[_node.x][_node.y] == )
  58. {
  59. return ;
  60. }
  61. node temp;
  62. temp.x = _node.x+_m[_node.x][_node.y];
  63. temp.y = _node.y;
  64. if(temp.x < n)
  65. {
  66. if(dp[temp.x][temp.y] == )
  67. {
  68. dp[_node.x][_node.y] += dfs(temp);
  69. }
  70. else
  71. {
  72. dp[_node.x][_node.y] += dp[temp.x][temp.y];
  73. }
  74. }
  75. temp.x = _node.x;
  76. temp.y = _node.y+_m[_node.x][_node.y];
  77. if(temp.y < n)
  78. {
  79. if(dp[temp.x][temp.y] == )
  80. {
  81. dp[_node.x][_node.y] += dfs(temp);
  82. }
  83. else
  84. {
  85. dp[_node.x][_node.y] += dp[temp.x][temp.y];
  86. }
  87. }
  88.  
  89. return dp[_node.x][_node.y];
  90. }

POJ 2704的更多相关文章

  1. POJ 2704 Pascal's Travels 【DFS记忆化搜索】

    题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  2. poj 2704 Pascal's Travels_记忆化搜索

    一道简单但是题意蛋疼的题目 题意:给你个n*n的图,开始在左上角,要求走到右下角有多种走法,图上的数表示走几步,只能向右或向下走. #include<iostream> #include& ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  5. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  6. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  7. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  8. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  9. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

随机推荐

  1. 用react脚手架新建项目

    1.全局安装 create-react-app脚手架 [可能需要管理员权限]npm install -g create-react-app 2.创建项目 create-react-app projec ...

  2. mysql mybatis useGeneratedKeys Field 'ID' doesn't have a default value的问题

    原因是:创建表时没有让id自动增长: CREATE TABLE `STORAGE_VIRTUAL` ( `ID` ) NOT NULL AUTO_INCREMENT, `STORAGE_ID` ) N ...

  3. s5-14 链路状态路由选择

    为什么DV逐渐让位于LS? DV  站的不高,看得不远  完全相信邻居 LS  想办法站得高,看更远  多高.多远?  怎么做? 链路状态路由(Link State) 主要思想 发现 它的邻 ...

  4. BZOJ 2301 [HAOI2011]Problem b (分块 + 莫比乌斯反演)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 6519  Solved: 3026[Submit] ...

  5. 容器,表格 ,div,元素可左右拖动,滚动 css

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  6. js读取后端写入cookie出现乱码

    设置字符编码集即可 Cookie cookie = new Cookie("user",URLEncoder.encode(nMessage, "UTF-8") ...

  7. 队列<一>

    这里用的递归法,采用两种版本,一种是C语言,一种是C++:但是,用C语言没有“引用”,所以采用的是指向指针的指针:而C++具备“引用”,所以直接用&引用,简洁: 先看C++的代码: BiTre ...

  8. Android自定义视图一:扩展现有的视图,添加新的XML属性

    这个系列是老外写的,干货!翻译出来一起学习.如有不妥,不吝赐教! Android自定义视图一:扩展现有的视图,添加新的XML属性 Android自定义视图二:如何绘制内容 Android自定义视图三: ...

  9. 5、Makefile基础知识汇总(转自陈皓总述)

    一.Makefile里有什么? Makefile里主要包含了五个东西:显式规则.隐晦规则.变量定义.文件指示和注释. 1.显式规则.显式规则说明了,如何生成一个或多的的目标文件.这是由Makefile ...

  10. spring boot thymeleaf

    引入支持 <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spr ...