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;
 }


光纤弯曲损耗原理、测试与工程规避实战指南 在光纤通信系统中,光信号传输依赖于纤芯内的全反射原理。当光纤发生过度弯曲时,会破坏全反射条件,导致光功率泄漏,产生弯曲损耗。这一物理机制直接影响链路的信噪比与传输稳定性,是光网络设计与运维中的关键考量因素。从技术价值看,理解并控制弯曲损耗对于保障FTTH、数据中心及5G前传等场景的链路预算至关重要。工程实践中,需通过光功率计与光时域反射仪(OTDR)等仪表进行量化测试与精确定位。针对布线中常见的宏弯与微弯问题,需在施工时严格控制弯曲半径、采用抗弯光纤(如G.657系列),并在运维中结合可视故障定位仪(VFL 阅读详情

相关推荐

Realtek RTD1319D芯片解析:H.266与AV1双解码的机顶盒SoC

视频编解码技术是数字媒体传输的核心,H.266/VVC作为新一代标准,相比H.265提升50%压缩效率,显著降低带宽需求。其实现原理依赖于专用硬件解码器和并行处理架构,在超高清视频传输领域具有重要价值。Realtek RTD1319D作为首款商用H.266处理器,采用异构计算设计,集成四核ARM CPU和独立视频处理单元,同时支持AV1解码,兼顾市场兼容性。该SoC特别适合4K机顶盒、数字标牌等应用场景,其HDMI 2.1a接口和DVB解调器为超高清内容传输提供完整解决方案。开发时需注意散热设计和内存配置优

weixin_42591413的博客 690

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

中科蓝讯蓝牙开发:从源码到固件的自动化构建链路解析

本文详细解析了中科蓝讯AB530X蓝牙芯片从源码到最终固件的完整自动化构建链路。通过剖析prebuild.bat、GCC编译、postbuild.bat等关键环节,阐述了资源打包、配置生成、代码编译与固件合成的全过程,并重点介绍了如何实现一键编译与自动下载,为开发者高效进行嵌入式蓝牙开发提供清晰指南。

weixin_29193259的博客 140

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

10倍开发者的 Dify 魔法书:从零构建全栈 AI 应用

“不懂底层算法,也能开发爆款 AI 应用吗?” 答案是:绝对可以。 Dify 正在重新定义 AI 应用的开发范式——通过可视化的低代码平台,将原本需要数周的开发周期压缩到几小时。无论你是前端、后端、产品经理,还是渴望破局的独立开发者,这都是你不可错过的红利。 我们将手把手教你利用 Dify 快速接入百模大战,零代码搭建企业级知识库,并一键发布你的专属 AI 助手、智能客服和自动化工作流。 告别重复造轮子,掌握 Dify,一个人就是一支 AI 团队。现在上车,开启你的 10 倍速开发之旅!

davidwang456的专栏 789

24、流化催化裂化的分子建模

本文探讨了流化催化裂化(FCC)的分子建模方法,重点分析了如何通过机理建模和模型修剪策略(如反应规则和随机规则)来减少计算复杂度,同时保持化学意义。文章还介绍了定量结构反应性关联(QSRC)在动力学参数确定中的应用,以及结焦对催化剂活性的影响。通过这些方法,FCC反应模型能够在预测产物分布的同时,显著提高计算效率。

s8t9u0v1w的博客 150

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 478

Pytorch实现之SRGAN+CBAM的结构设计

在SRGAN的残差连接中加入了CBAM注意力机制,同时设计了四类损失来训练。

LJ1147517021的博客 581

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

RK3588开发笔记-Buildroot编译Qt5WebEngine-5.15.10

Rockchip RK3588是一款强大的多核处理器,广泛应用于边缘计算、人工智能、嵌入式系统等领域。为了在RK3588上运行自定义的Linux系统,并使用Qt5WebEngine进行Web内容渲染,Buildroot是一个非常合适的工具。本文将详细介绍如何使用Buildroot编译并配置Qt5WebEngine-5.15.10。Qt5WebEngine是Qt框架中的一个模块,它提供了一个功能强大的Web浏览器引擎,允许开发者在Qt应用程序中嵌入和显示现代网页内容。

flypig has a dream! 1168

十一、Cadence ic 617以及assura使用总结

1.617的端口和514不同,没有网络属性,使用时不能直接放在原理图上,如果要直接放在图上要接线并且放上标签。2.617的端口也不能直接放在线上,514中将端口直接放在线上是可以使端口和线连接,但617看似连接,但拉出来线没有交点,实际上没有连接。这里set switches里的选项表示不同的模块,也就是选择一个就只对这一部分进行DRC验证,要验证整个版图的DRC就要把所有的选项选中,然后一个个改正。LVS中也是一样,要全部选中改正。

0 2299

求组合数的方法

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的博客 309

FANUC机器人S523 新款PN板卡与西门子PLC通信配置介绍

FANUC机器人S523 新款PN板卡与西门子PLC通信配置介绍

Robot_PLC_HMI_Automation 386

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 911

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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 1949

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ 1942 Paths on a Grid 组合数

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

水 961

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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 601

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

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

happy_lcj 940

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、付费专栏及课程。

余额充值
⌂ 换网址