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 ...
随机推荐
- 2018.12.19 codeforces 1092F. Tree with Maximum Cost(换根dp)
传送门 sbsbsb树形dpdpdp题. 题意简述:给出一棵边权为1的树,允许选任意一个点vvv为根,求∑i=1ndist(i,v)∗ai\sum_{i=1}^ndist(i,v)*a_i∑i=1n ...
- php 类与对象 面向对象编程 简单例子
<?php class Foo { //类 名称为Foo public $aMemberVar = 'aMemberVar Member Variable'; //类变量 public $aFu ...
- C#-VS异常处理
VS异常处理 常规 try 可能会产生异常的代码,当一行产生异常,这行下面的代码不执行,转到catch开始执行 catch(system.Exception e) e.message ...
- 闭合浮动的方法css
浮动是一个有意思(你也可以说它很麻烦)的CSS属性,任何元素设置了浮动,层级就提高了,会影响它后面没设置浮动的元素,这些倒霉的被影响者会跑到浮动层的下面去(当然IE6.IE7除外),那解决方法呢? 常 ...
- mysql问题处理记录
1.使用 navicate 导出 csv 文件用 excel 打开乱码 由于excel默认编码是gbk,而navicate导出数据默认编码是utf-8,因此... 解决办法: 使用WPS打开文件,然后 ...
- 【repost】DOM CRUD
//DOM 的 CRUD // c 创建create // 1.直接往body中动态的添加标签(可以是任意类型)document.write('helloWorld');document.write( ...
- Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
- W-TinyLFU——设计一个现代的缓存
缓存设计是个基础架构领域里的重要话题,本号之前也有谈论过相关话题,点击原文可以看之前的介绍. 近日,HighScalability网站刊登了一篇文章,由前Google工程师发明的W-TinyLFU—— ...
- Android 百度云推送
http://developer.baidu.com/wiki/index.php?title=docs/cplat/push/sdk/clientsdk. public class DemoAppl ...
- STL容器之一vector
STL中最简单也是最有用的容器之一是vector<T>类模板,称为向量容器,是序列类型容器中的一种. 1.vector<T> 对象的基本用法(1)声明:vector<ty ...