POJ - 1942 D - Paths on a Grid 组合数

POJ1942-Paths on a Grid 北大POJ1942-Paths on a Grid 解题报告+AC代码 立即下载

Paths on a Grid
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 25331 Accepted: 6324

Description

Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b) 2=a 2+2ab+b 2). So you decide to waste your time with drawing modern art instead. 

Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left: 

Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?

Input

The input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.

Output

For each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right or one unit up? You may safely assume that this number fits into a 32-bit unsigned integer.

Sample Input

5 4
1 1
0 0

Sample Output

126
2

Source


第一次做这个题是dp做的,学习了组合数,发现组合数更简单

无论怎么走肯定要走n+m这么长的路,在这么长的路里选n个向下走的

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
ll myc(ll n,ll r)
{
	ll sum=1;
	for(int i=1;i<=r;i++)
	{
		sum=sum*(n-i+1)/i;
	}
	return sum;
}
int main()
{
	ll a,b;
	while(~scanf("%lld %lld",&a,&b),a+b)
	{
		if(a==0||b==0)
		printf("1\n");
		else
		printf("%lld\n",myc(a+b,a));
	}
	return 0;
 }


双目相机立体匹配算法概述(含Python代码) 立体匹配任务是计算机视觉中的一个重要问题,旨在从一对具有相同场景的图像中估计每个像素的视差(disparity)。本文对现有的传统算法和深度学习算法进行了综述,以便于各位选择合适的立体匹配算法用于深度估计或三维建模。 阅读详情

相关推荐

帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案

帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案 入门基础 11.多选题 以下方式中属于FineReport中预览模式的有( ) 分页预览、填报预览、新填报预览、数据分析、移动端预览 16.判断题 FineReport报表工具必须购买激活码后才能使用。 错误,可以免费获取激活码。 29.单选题 FineReport是一款利用( )语言开发的报表工具。java 41.多选题 访问帮助文档的方式有哪些?设计器中社区菜单下-帮助文档;直接访问http://help.finere

qq_37485720的博客 2万+

poj1942

Paths on a Grid Description Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's

◆◇丶生如夏花。谁来订阅我的悲伤 1124

如何实现MCGS与S7-200SMART PLC以太网多台通信控制?

第九步:(设备工具箱—设备管理—鼠标依次点击通用TCP/IP父设备—西门子_ Smart200到设备窗口里面去)数据类型:第0位(指PLC地址变量小数点后面的位数,例如我地址是M0.0,那么在数据类型应填写通道的第00位)第十步:(鼠标双击打开通用TCPIP父设备0--[通用TCP/IP父设备]进入通信配置)通道地址:0(指小数点前面起始字节的地址,例如我地址是M0.0,那么应在通道地填写0)。第七步:(选择通用TCP/IP父设备,点击新增,右侧选定设备就会自动添加进去。

u010670857的博客 6716

POJ 1942 Paths on a Grid 解题报告(double妙用)

题目大意:每次可以向上走,向右走。问有多少种走法。     解题报告:简单来说就是求Cmn。不过注意数据范围,unsigned int,用int会超。     简单做法就是循环较小的数来求,原来写的代码如下: #include #include #include #include using namespace std; bool vis[200];; int main() {

SF-_- 的 ACM 博客 974

ORB-SLAM3单目+IMU实战:从数据加载到位姿优化的完整流程解析

本文详细解析了ORB-SLAM3单目+IMU模式的完整实战流程。从EuRoC等数据集的数据格式准备、系统启动与数据流入口,到帧构建、IMU预积分、视觉-惯性联合初始化,再到基于运动模型的跟踪、局部地图优化及多线程协同,提供了从环境配置到代码解读的全面指南,并分享了参数调优与性能分析的实用调试经验。

weixin_29085151的博客 296

BGE-M3 文本情感分类实战:预训练模型微调,导出ONNX并测试

本文介绍了如何基于BGE-M3开源模型实现一个简单的二分类情感分析任务,展示了NLP中经典的“预训练 + 微调”范式。首先,加载预训练模型和分词器,并构建分类头整合到模型中。接着,进行数据预处理并构建DataLoader。然后,定义优化器、损失函数和训练循环,进行模型微调。微调过程中,可以选择基于[CLS] token的单特征提取或基于池化策略的多特征融合。最后,通过验证与推理评估模型性能,并导出ONNX模型以适应生产环境。BGE-M3在语义表征任务中表现优异,适合作为文本分类、语义搜索等下游任务的基础模型

大鹏的专栏 1403

poj 1942 Paths on a Grid

题目链接:点击打开链接 Description Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's expl

Vision 476

Autodesk激活无无网络选项?许可类型与脱机激活排查修复指南

软件许可激活是保障正版授权正常使用的核心环节,常见的授权模式包括单机版许可和网络版许可,两者在认证机制和应用场景上有所区别。单机版离线授权依托 FlexNet Licensing Service 等底层服务组件,在断网或内网环境下为用户提供可靠的技术支持与授权验证路径。然而在实际部署中,激活窗口并不总是显示“无网络激活方式”入口,这可能与许可类型选择、网络环境干扰、组件安装残留或系统时间偏差有关。理解入口的动态呈现逻辑与排查顺序,有助于在 AutoCAD、Revit 等 Autodesk 产品中高效解决脱机

weixin_28709649的博客 355

POJ - 1942 Paths on a Grid (组合数学)

POJ - 1942 Paths on a Grid (组合数学) Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he’...

weixin_43179892的博客 279

国科大学习资料--高级软件工程-复习题概念解释答案

国科大学习资料–高级软件工程(罗铁坚 魏峻 刘丹)-复习题概念解释答案 1. 敏捷开发方法与Scrum方法 a.敏捷是一种强调轻量的过程方法论,它强调拥抱变化而不是与之对抗,通过有效的沟通发挥群体的智慧。敏捷方法采用迭代/增量开发的过程模型。敏捷宣言是:个体和交互高于流程和工具;工作的软件高于详尽的文档;客户合作高于合同谈判;响应变化高于遵循计划。 虽然右边的也有价值,但是认为左边的更有价值。 b.Scrum(Schwaber和Beedle)是管理两个披萨规模(4-9人)的软件开发团队的方法,它高频率的短会

无名何许人的博客 1443

【Burp入门第三十七篇】AutoRepeater插件安装使用教程+越权实战案例

AutoRepeater 通过接收满足特定条件的请求,按照预设的基础替换规则对请求进行处理。在接收到匹配请求后,它首先应用基础替换,然后针对每个定义的替换创建请求副本并应用该替换操作,从而实现对不同参数的修改和请求的重复发送,以此来全面检测 Web 应用的授权情况。1、自动化请求重复:能自动复制、修改并重发 HTTP 请求,避免了手动重复操作的繁琐,大大提高了 Web 应用授权测试的效率。2、灵活参数替换:可灵活改变邮箱地址、账号身份、角色、URL 和 CSRF 令牌等关键参数。

等风来 2035

求组合数的方法

1.暴力 根据阶乘公式展开,时间复杂度较高,且容易炸掉long long 2.借用double暴力来求 http://icpc.upc.edu.cn/problem.php?cid=1438&pid=9 题目描述 Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years

TimWcx的博客 308

tar解压报错 gzip: stdin: unexpected end of file tar: Unexpected EOF in archive

错误现象: [root@centos7-xinsz08 ~]# tar xf prometheus-2.7.2.linux-amd64.tar.gz gzip: stdin: unexpected end of file tar: 归档文件中异常的 EOF tar: 归档文件中异常的 EOF tar: Error is not recoverable: exiting now 错误原因排查 ...

互联网老辛 2万+

POJ 1942 Paths on a Grid (组合数学)

题目地址:POJ 1942 这题就是求组合数c(n,n+m),高中的时候做过这种组合题,现在居然推不出来了。。sad。。。时光催人老。。。。 代码如下: #include #include #include #include #include #include #include #include #include using namespace std; #define

scf0920 910

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

POJ 1942-Paths on a Grid(组合数学)

Paths on a Grid Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1942 Appoint description:  System Crawler  (2015-05-24) Descrip

Rocky0429 1948

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

POJ 1942 Paths on a Grid 组合数

这道题其实就是组合数,题目给了m,n,实际上路径的长度已经确定了,就是m+n,但在这些路径中必须有m个向右走的,n个向上走的,这样才能到达终点 这就变成了求组合数C(m + n, n) 其中n必须是m,n中较小的那个,这样速度还快些 在求组合数的时候,要避免的是越界问题,所以每次我都是先除,然后再乘,除的时候也不能直接除,一定要求了公约数后再除,这样才是整除。 /* ID: sdj22251

水 961

POJ-1942 Paths on a Grid 组合数

  题目链接:http://poj.org/problem?id=1942   水题一枚,递推求解组合数即可。 1 //STATUS:C++_AC_16MS_184KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h&g...

weixin_30813225的博客 116

poj 1942 Paths on a Grid

<br />求组合数<br />下面的博客写了好几种方法<br />http://hi.baidu.com/peacefulby/blog/item/3a4b4dc9409c5b1f7f3e6fc2.html<br /><br />#include<iostream> using namespace std; __int64 C(__int64 a,__int64 b) { if(b==0) return 1; else if(b==1) return a; else r

a_new 600

poj 1942 Paths on a Grid (组合数学)

题意:给一个n*m的矩阵网格,问有多少种方法从左下角走到右上角。 注意n,m都是32位无符号整形范围内,可以直接用64位存, 从左下角走到右上角的过程中,每次只能向上或向右走一个单位长度。 分析:向上走要走n步,向右走要走m步,就相当于n+m个位置选n个向上或选m个向右

happy_lcj 939

POJ 1942 Paths on a Grid

题目链接http://poj.org/problem?id=1942 题意 输入边长 有多少种走法 思路 组合数模板 View Code 1 #include<stdio.h> 2 int main() 3 { 4 __int64 n,m,s,t,i,sum; 5 while(~scanf("%I64d%I64d",&n,&amp...

weixin_30773135的博客 75

POJ - 1942 D - Paths on a Grid

Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b...

weixin_30466953的博客 99

poj1942——Paths on a Grid(求阶乘)

DescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he’s explaining that (a+b)2=a

Beyond the Sora 994

POJ 1942:Paths on a Grid

Paths on a Grid Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1942 Appoint description:  System Crawler  (2015-09-25) Descr

所谓梦想,就是永不停息的疯狂。。。。。 440
上一篇: POJ - 1850 Code 组合数
下一篇: POJ - 1836 Alignment
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值