当前位置:网站首页>信息学奥赛一本通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;
}
边栏推荐
- QRcode custom QR code middle picture
- Ogg synchronize MySQL data to greenplus
- Redis' cache avalanche, cache breakdown, cache penetration, cache preheating, and cache degradation
- 阿里云体验有奖:使用PolarDB-X与Flink搭建实时数据大屏
- Uniapp problem list and experience
- Research Report on research and development prospect of China's urea dioxide industry (2022 Edition)
- 如果我在佛山,到哪里开户比较好?究竟网上开户是否安全么?
- Chinese garbled code output from idea output station
- Evaluation index of high concurrency software (website, server interface)
- Transport layer user datagram protocol (UDP)
猜你喜欢

卫龙更新招股书:年营收48亿 创始人刘卫平家族色彩浓厚

Paper study -- accurate accounting of annual total runoff control rate considering the interannual variation characteristics of rainfall

Uncover the secret! Pay attention to those machines under the membership system!

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

Alibaba cloud experience Award: use polardb-x and Flink to build a large real-time data screen

June 27 talk SofiE
![[practical chapter of correlation analysis] why can't Bi software do correlation analysis](/img/f2/4f99deb63b1beffae90b8a1fb270d1.png)
[practical chapter of correlation analysis] why can't Bi software do correlation analysis

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

MySQL 数据库 - 通用语法 DDL DML DQL DCL

熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
随机推荐
Laravel - composer installs the specified laravel version
《canvas》之第12章 其他应用
Yi Ming ang Ke rushed to Hong Kong shares: loss of 730million in the year Lilly and sunshine life insurance were shareholders
I log in to the RDB database and prompt that the master account authorization is required. How do I know who to call?
Chinese garbled code output from idea output station
高并发软件(网站,服务器端接口)的评价指标
June 27 talk SofiE
PostgreSql学习(基于菜鸟课程)
Laravel - Composer 安装指定 Laravel 版本
Mysql database - general syntax DDL DML DQL DCL
华理生物冲刺科创板:年营收2.26亿 拟募资8亿
. Net program configuration file operation (INI, CFG, config)
Deploy redis sentry in k8s
《canvas》之第11章 canvas状态
[blackduck] configure the specified Synopsys detect scan version under Jenkins
论文学习——考虑场次降雨年际变化特征的年径流总量控制率准确核算
Interview shock 61: tell me about MySQL transaction isolation level?
VQA needs not only pictures, but also external knowledge! University of Washington & Microsoft proposed revive, using gpt-3 and wikidata to help answer questions
三角函数对应在平面坐标上画圆
网易严选离线数仓质量建设实践