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 ...
随机推荐
- 假期训练五(poj-1077bfs+康拓展开,hdu-2577dp)
题目一:传送门 思路:主要是找到状态, 考虑字母有两种状态,大写和小写, 从小写变为大写的变化方式有两种:保持cap状态,或者按住shift键: 从小写变为大写也有一种变化方式:按住shift键: 看 ...
- oracle在exp导出时报错PLS-00201: identifier 'EXFSYS.DBMS_EXPFIL_DEPASEXP' must be declared
报错如下信息: EXP-00008: ORACLE error 6550 encounteredORA-06550: line 1, column 14:PLS-00201: identifier ' ...
- iframe父子元素获取
jquery.js调用iframe父窗口与子窗口元素的方法 1. jquery在iframe子页面获取父页面元素代码如下: $("#objid",parent.document) ...
- AngularJS封装UEditor
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- poj2774 sa模版
学习地址:http://blog.csdn.net/yxuanwkeith/article/details/50636898 #include<iostream> #include< ...
- Linux 禁ping和开启ping操作
方法一: # echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all 如果要恢复,只要: # echo 0 > /proc/sys/net ...
- noip第27课作业
1. 繁忙的都市 [问题描述] 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个 ...
- 谈谈HashMap线程不安全的体现
原文出处: Hosee HashMap的原理以及如何实现,之前在JDK7与JDK8中HashMap的实现中已经说明了. 那么,为什么说HashMap是线程不安全的呢?它在多线程环境下,会发生什么情况呢 ...
- html5打开摄像头并用canvas模拟拍照 - 转
<video id="video" width="640" height="480" autoplay></video&g ...
- pickle 继承
1.什么是方法,什么是函数 class Foo: def chi(self): print("我是吃") @staticmethod def static_method(): pa ...