codevs——1267 老鼠的旅行(棋盘DP)
You are a mouse that lives in a cage in a large laboratory.
你是一只生活在笼子里的实验室老鼠。
The laboratory is composed of one rectangular grid of square cages, with a total of R rows and C columns of cages (1 ≤ R,C ≤ 25).
实验室是一个R行C列的格子矩阵(1 ≤ R,C ≤ 25). 每个格子是一个笼子. (尼玛还要我活么……)
To get your exercise, the laboratory owners allow you to move between cages.
为了让你锻炼身体,实验室管理员允许你在笼子之间移动。
You can move between cages either by moving right between two adjacent cages in the same row, or by moving down between two adjacent cages in the same column.
你只能向右和向下移动。
You cannot move diagonally, left or up.
你不能斜着移动,也不能向上和向左移动。
Your cage is in one corner of the laboratory, which has the label (1,1) (to indicate top-most row, left-most column).
你所在的笼子是实验室的左上角,标记为(1,1)
You would like to visit your brother who lives in the cage labelled (R,C) (bottom-most row, right-most column), which is in the other corner diagonally.
你想去右下角的笼子(R,C)里找你的女朋友(尼玛老鼠也有女盆友么!!!)
However, there are some cages which you cannot pass through, since they contain cats.
但是有一些笼子是不能经过的,因为里面有猫(谁说老鼠怕猫么,还有,管理员有毛病么……)
Your brother, who loves numbers, would like to know how many different paths there are between your cage and his that do not pass through any cat cage. Write a program to compute this number of cat-free paths.
你女朋友很爱数学,她想要知道有多少条不同的路径可以从你的笼子到达她的笼子。写一个程序来计算吧。(这样的女朋友不要也罢……)
The first line of input contains two integers R and C, separated by one space representing the number of rows and columns (respectively). On the second line of input is the integer K, the number of cages that contain cats. The next K lines each contain the row and column positions (in that order) for a cage that contains a cat. None of the K cat cages are repeated, and all cages are valid positions. Note also that (1,1) and (R,C) will not be cat cages.
第一行包含2个整数R和C,第二行一个整数K,代表包含猫的笼子的个数,接下来K行包含K个不同的位置信息,代表K个包含猫的笼子的位置信息,注意(1,1)和(R,C)这两个位置是不会有猫的, 否则出题者就没法活了……
Output the non-negative integer value representing the number of paths between your cage at position (1,1) and your brother’s cage at position (R,C). You can assume the output will be strictly less than 1 000 000 000.
输出一个非负整数代表你可以去你女朋友笼子里和她啪啪啪的路径数目,你可以假设这个输出会严格小于1,000,000,000。
样例输入 1:
2 3
1
2 1
样例输入 2:
3 4
3
2 3
2 1
1 4
样例输出 1: 2
样例输出 2: 1
分类标签 Tags 点此展开
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
][],x,y;
][];
int main()
{
scanf("%d%d",&r,&c);
scanf("%d",&k);
;i<=k;i++)
{
scanf("%d%d",&x,&y);
a[x][y]=;
}
f[][]=;
;i<=r;i++)
;j<=c;j++)
{
) f[i][j]=max(f[i][j-],f[i][j]);
) f[i][j]=max(f[i-][j],f[i][j]);
&&j>) f[i][j]=f[i-][j]+f[i][j-];
) f[i][j]=;
}
printf("%d",f[r][c]);
;
}
思路:
说是动归,其实就是递推!!!!
look!由于一个点只能往下走或往右走,所以这个点的方案数等于他上面的点的方案数+他左边的点的方案数
由此:可得动态转移方程(递推式):f[i][j]=f[i-1][j]+f[i][j-1];
当他在第一行时和第一列时只能从他的左边,上边来,所以特判;
当他遇到猫时,此时的方案数为0;
codevs——1267 老鼠的旅行(棋盘DP)的更多相关文章
- codevs 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description You are a mouse that lives in a cage in ...
- 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛 题目描述 Description You are a mouse that lives in a cage in a large lab ...
- codevs——T1267 老鼠的旅行
http://codevs.cn/problem/1267/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
- codevs——1010 过河卒(棋盘DP)
2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 如图,A 点有 ...
- codevs——1169 传纸条(棋盘DP)
2008年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 小渊和小 ...
- codevs——2853 方格游戏(棋盘DP)
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 菜菜看到了一个游戏,叫做方格游戏~ 游戏规则是这样的: 在一个n*n的 ...
- codevs——1220 数字三角形(棋盘DP)
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 如图所示的数字三角形,从顶部出发,在每一结点可以选择向左走或 ...
- dp练习(2)——老鼠的旅行
1267 老鼠的旅行(来源:codevs) #include "bits/stdc++.h" using namespace std; ][]; ][]; int main() { ...
- 炮(棋盘DP)
一直以为自己写的就是状态压缩,结果写完才知道是个棋盘dp 首先看一下题目 嗯,象棋 ,还是只有炮的象棋 对于方案数有几种,我第一个考虑是dfs,但是超时稳稳的,所以果断放弃 然后记得以前有过和这个题差 ...
随机推荐
- AndroidStudio和IDEA的初始设置
一.第一次安装: Android Studio安装完成后,第一次启动AS前,为了避免重新下载新版本的SDK,需要做如下操作: AS启动前,打开安装目录,请先将bin目录的idea.properties ...
- 《鸟哥的Linux私房菜》学习笔记(5)——权限管理
一.权限的基本概念 权限:访问计算机资源或服务的访问能力. Linux中,每一个资源或者服务的权限, ...
- hdu1950Bridging signals(求最长上升自序列nlogn算法)
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Redis实现之数据库(三)
过期键删除策略 在Redis实现之数据库(二)一小节中,我们知道了数据库键的过期时间都保存在过期字典中,又知道了如果根据过期时间去判断一个键是否过期,现在剩下的问题是:如果一个键过期了,那么它什么时候 ...
- windows服务安装卸载
到C盘下找到对应的开发VS的installutil.exe文件,复制到程序的执行文件(*.exe)相同目录下在开始程序中找到VS命令提示工具 转到程序的执行文件(*.exe)目录下 C:\>cd ...
- Pipenv 学习笔记
个人笔记,胡言乱语.并不是什么教学向文章.. 前言 在学习了 Python.Java 后,会发现 Java 有很成熟的项目构建工具,以前是使用 xml 的 Maven,现在又出现了使用 groovy ...
- Could not connect to Redis at 127.0.0.1:6379: Connection refused
启动redis: redis-server ../redis.conf redis启动成功后 执行命令行redis-cli报:Could not connect to Redis at 127.0. ...
- BZOJ 1192:[HNOI2006]鬼谷子的钱袋(数学)
鬼谷子的钱袋Description鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政.有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商行)将要举行一场拍卖会 ...
- 【SPOJ1297】Palindrome (SA+RMQ)
求最长回文串.把原串翻转后,加在原串后面,中间插入一个辨别字符.然后求SA,Height.然后枚举每个字母作为回文串中心,分长度为奇数和偶数去讨论:奇数求 suffix(i)和suffix(n-i+1 ...
- [HDU3480] Division [四边形不等式dp]
题面: 传送门 思路: 因为集合可以无序选择,所以我们先把输入数据排个序 然后发先可以动归一波 设$dp\left[i\right]\left[j\right]$表示前j个数中分了i个集合,$w\le ...