当前位置:网站首页>信息学奥赛一本通1194:移动路线
信息学奥赛一本通1194:移动路线
2022-06-29 14:39:00 【冯耀文】
题目来源:http://ybt.ssoier.cn:8088/problem_show.php?pid=1194
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 8666 通过数: 6598
【题目描述】
X桌子上有一个m行n列的方格矩阵,将每个方格用坐标表示,行坐标从下到上依次递增,列坐标从左至右依次递增,左下角方格的坐标为(1,1),则右上角方格的坐标为(m,n)。
小明是个调皮的孩子,一天他捉来一只蚂蚁,不小心把蚂蚁的右脚弄伤了,于是蚂蚁只能向上或向右移动。小明把这只蚂蚁放在左下角的方格中,蚂蚁从
左下角的方格中移动到右上角的方格中,每步移动一个方格。蚂蚁始终在方格矩阵内移动,请计算出不同的移动路线的数目。
对于1行1列的方格矩阵,蚂蚁原地移动,移动路线数为1;对于1行2列(或2行1列)的方格矩阵,蚂蚁只需一次向右(或向上)移动,移动路线数也为1……对于一个2行3列的方格矩阵,如下图所示:
【输入】
输入只有一行,包括两个整数m和n(0 < m+n ≤ 20),代表方格矩阵的行数和列数,m、n之间用空格隔开。
【输出】
输出只有一行,为不同的移动路线的数目。
【输入样例】
2 3【输出样例】
3【分析题目】

根据以上分析,发现以下规律:

发现规律是a[i][j]=a[i-1][j]+a[i][j-1],于是乎,代码就出来啦。
【代码】
#include<iostream>
using namespace std;
long long a[20][20];
int main()
{
for(int i=1;i<=20;i++)
{
for(int j=1;j<=20;j++)
{
if(i==1||j==1) a[i][j]=1;
else a[i][j]=a[i-1][j]+a[i][j-1];
}
}
int n,m;
cin>>n>>m;
cout<<a[n][m]<<endl;
return 0;
}
边栏推荐
- delphi7中 url的编码
- Nuscenes configuration information about radar
- You need to know about project procurement management
- .NET程序配置文件操作(ini,cfg,config)
- Research Report on research and development prospect of China's urea dioxide industry (2022 Edition)
- Deploy redis sentry in k8s
- 类模板案例-【数组类封装】
- Interview shock 61: tell me about MySQL transaction isolation level?
- Uncover the secret! Pay attention to those machines under the membership system!
- idea输出台输出中文乱码问题
猜你喜欢

云上第一课 | 建个小破站有多简单?云计算老司机带你一小时搞定

Zhimeng dedecms resource material tutorial download website template source code (with mobile terminal) with installation tutorial

Methods of accessing external services in istio grid

织梦dedecms资源素材教程下载网站模板源码(带手机移动端)附安装教程

二级指针

在平面坐标上画斜线

June 27 talk SofiE

揭秘!付费会员制下的那些小心机!

Heavyweight! The latest SCI impact factors were released in 2022, and the ranking of the three famous journals NCS and the top10 of domestic journals has changed (the latest impact factors in 2022 are

Illustration of Ctrip quarterly report: net revenue of RMB 4.1 billion has been "halved" compared with that before the outbreak
随机推荐
Imitation headline news information DZ template discuz news information business version GBK template source code
redis在window和Linux环境下的安装
Query function of Excel vlookup
Asynchronous artifact completable future
《canvas》之第8章 像素操作
仿头条新闻资讯dz模板 Discuz新闻资讯商业版GBK模板源码
Chinese garbled code output from idea output station
Ogg synchronize MySQL data to greenplus
第五届中国软件开源创新大赛 | openGauss赛道直播培训
Netease strict selection offline data warehouse quality construction practice
FIFO implementation with single port RAM
June 27 talk SofiE
华理生物冲刺科创板:年营收2.26亿 拟募资8亿
Chapter 5 text operation of canvas
卫星运动的微分方程
Configuration tutorial for swagger2
中国软冰淇淋市场预测与投资前景研究报告(2022版)
mysql 备份与还原
Interview shock 61: tell me about MySQL transaction isolation level?
宜明昂科冲刺港股:年内亏损7.3亿 礼来与阳光人寿是股东