POJ 2704
- #include <iostream>
- #include <string>
- #define LL long long
- #define MAXN 100
- using namespace std;
- int dis[][] = {,,,};
- int _m[MAXN][MAXN];
- LL dp[MAXN][MAXN];
- struct node
- {
- int x;
- int y;
- };
- int n;
- LL dfs(node _node);
- //bool mark[MAXN][MAXN];
- int main()
- {
- //freopen("acm.acm","r",stdin);
- int i;
- int j;
- string s;
- while(cin>>n)
- {
- getchar();
- if(n == -)
- {
- break;
- }
- memset(dp,,sizeof(dp));
- for(i = ; i < n; ++ i)
- {
- getline(cin,s);
- for(j = ; j < n; ++ j)
- {
- //cin>>_m[i][j];
- _m[i][j] = s[j]-'';
- }
- }
- node b;
- b.x = ;
- b.y = ;
- cout<<dfs(b)<<endl;
- }
- }
- LL dfs(node _node)
- {
- if(_node.x == n- && _node.y == n-)
- {
- return ;
- }
- if(_m[_node.x][_node.y] == )
- {
- return ;
- }
- node temp;
- temp.x = _node.x+_m[_node.x][_node.y];
- temp.y = _node.y;
- if(temp.x < n)
- {
- if(dp[temp.x][temp.y] == )
- {
- dp[_node.x][_node.y] += dfs(temp);
- }
- else
- {
- dp[_node.x][_node.y] += dp[temp.x][temp.y];
- }
- }
- temp.x = _node.x;
- temp.y = _node.y+_m[_node.x][_node.y];
- if(temp.y < n)
- {
- if(dp[temp.x][temp.y] == )
- {
- dp[_node.x][_node.y] += dfs(temp);
- }
- else
- {
- dp[_node.x][_node.y] += dp[temp.x][temp.y];
- }
- }
- return dp[_node.x][_node.y];
- }
POJ 2704的更多相关文章
- POJ 2704 Pascal's Travels 【DFS记忆化搜索】
题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS Memory Limit: 65536K Tota ...
- poj 2704 Pascal's Travels_记忆化搜索
一道简单但是题意蛋疼的题目 题意:给你个n*n的图,开始在左上角,要求走到右下角有多种走法,图上的数表示走几步,只能向右或向下走. #include<iostream> #include& ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
随机推荐
- 用react脚手架新建项目
1.全局安装 create-react-app脚手架 [可能需要管理员权限]npm install -g create-react-app 2.创建项目 create-react-app projec ...
- mysql mybatis useGeneratedKeys Field 'ID' doesn't have a default value的问题
原因是:创建表时没有让id自动增长: CREATE TABLE `STORAGE_VIRTUAL` ( `ID` ) NOT NULL AUTO_INCREMENT, `STORAGE_ID` ) N ...
- s5-14 链路状态路由选择
为什么DV逐渐让位于LS? DV 站的不高,看得不远 完全相信邻居 LS 想办法站得高,看更远 多高.多远? 怎么做? 链路状态路由(Link State) 主要思想 发现 它的邻 ...
- BZOJ 2301 [HAOI2011]Problem b (分块 + 莫比乌斯反演)
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 6519 Solved: 3026[Submit] ...
- 容器,表格 ,div,元素可左右拖动,滚动 css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- js读取后端写入cookie出现乱码
设置字符编码集即可 Cookie cookie = new Cookie("user",URLEncoder.encode(nMessage, "UTF-8") ...
- 队列<一>
这里用的递归法,采用两种版本,一种是C语言,一种是C++:但是,用C语言没有“引用”,所以采用的是指向指针的指针:而C++具备“引用”,所以直接用&引用,简洁: 先看C++的代码: BiTre ...
- Android自定义视图一:扩展现有的视图,添加新的XML属性
这个系列是老外写的,干货!翻译出来一起学习.如有不妥,不吝赐教! Android自定义视图一:扩展现有的视图,添加新的XML属性 Android自定义视图二:如何绘制内容 Android自定义视图三: ...
- 5、Makefile基础知识汇总(转自陈皓总述)
一.Makefile里有什么? Makefile里主要包含了五个东西:显式规则.隐晦规则.变量定义.文件指示和注释. 1.显式规则.显式规则说明了,如何生成一个或多的的目标文件.这是由Makefile ...
- spring boot thymeleaf
引入支持 <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spr ...