poj1942——组合数学

Paths on a Grid
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 22473   Accepted: 5522

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=a2+2ab+b2). 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题意:从左下角到右上角的路径数目思路:本来用的dp,后来发现dp方程正是杨辉三角的递推公式。。处理C(n,k)最重要的是防止阶乘越界,用递推式是个不错的选择,但难以防止MLE,下面这种“先除后乘”再强制类型转换以前在codeforces上用过,这次居然没想起来。。。看了题解后才AC了。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>using namespace std;const int maxn=10200;
const int INF=(1<<28);typedef long long ll;
ll n,m;ll C(ll n,ll k)
{double res=1.0;if(k>n-k) k=n-k;ll a=n,b=k;while(b>0){res*=a*1.0/b;a--;b--;}if(res-(ll)res>0.5) res++;return res;
}int main()
{while(cin>>n>>m,n||m){cout<<C(n+m,n)<<endl;}return 0;
}

View Code

转载于:https://www.cnblogs.com/--560/p/4366373.html

poj1942——组合数学相关推荐

  1. 不畏浮云遮望眼--离散数学和组合数学

    不畏浮云遮望眼,基础很重要! 离散数学是算法和数据结构的基础,而算法和数据结构又是什么的基础?不解释了. 1.<离散数学及其应用> 作者: (美)Kenneth H. R 出版社: 机械工 ...

  2. szucodeforce训练1081C组合数学lucas定理,div2 627的D dfs +剪枝优化,697D Puzzles{dfs序+概率}

    给你n个方格排成一行,有m种颜色,然后要把这n个方格分成k+1段,每段涂不同的颜色,问有多少种方法. 组合数学Lucas定理 排列组合问题,首先要在n-1个位置里面选出k个位置当作段与段的分割点,然后 ...

  3. 【数学专题】组合数学与计数

    整理的算法模板合集: ACM模板 目录 AcWing 1307. 牡牛和牝牛(递推) AcWing 1308. 方程的解 AcWing 1309. 车的放置(组合数学,分类讨论) AcWing 131 ...

  4. 组合数学实验——二分图匹配算法

    2019独角兽企业重金招聘Python工程师标准>>> 大一时候写的代码,忽然翻了出来.... 算法:组合数学中文第4版 机械工业出版社 P234 ID就先隐藏掉了 // // // ...

  5. Sequence(组合数学,集合不同元素的个数)

    Sequence [组合数学] 时间限制: 3 Sec  内存限制: 128 MB 提交: 138  解决: 52 [提交][状态][讨论版] 题目描述 在某个夜黑月高的晚上,!!!,原谅我编不下去了 ...

  6. 【组合数学】指数生成函数 ( 指数生成函数求解多重集排列示例 2 )

    文章目录 一.指数生成函数求解多重集排列示例 2 参考博客 : 按照顺序看 [组合数学]生成函数 简要介绍 ( 生成函数定义 | 牛顿二项式系数 | 常用的生成函数 | 与常数相关 | 与二项式系数相 ...

  7. 【组合数学】指数生成函数 ( 指数生成函数求解多重集排列示例 )

    文章目录 一.指数生成函数求解多重集排列示例 参考博客 : 按照顺序看 [组合数学]生成函数 简要介绍 ( 生成函数定义 | 牛顿二项式系数 | 常用的生成函数 | 与常数相关 | 与二项式系数相关 ...

  8. 【组合数学】指数生成函数 ( 证明指数生成函数求解多重集排列 )

    文章目录 一.证明指数生成函数求解多重集排列 参考博客 : 按照顺序看 [组合数学]生成函数 简要介绍 ( 生成函数定义 | 牛顿二项式系数 | 常用的生成函数 | 与常数相关 | 与二项式系数相关 ...

  9. 【组合数学】指数生成函数 ( 指数生成函数性质 | 指数生成函数求解多重集排列 )

    文章目录 一.指数生成函数性质 二.指数生成函数求解多重集排列 参考博客 : 按照顺序看 [组合数学]生成函数 简要介绍 ( 生成函数定义 | 牛顿二项式系数 | 常用的生成函数 | 与常数相关 | ...

  10. 【组合数学】生成函数 ( 正整数拆分 | 重复有序拆分 | 不重复有序拆分 | 重复有序拆分方案数证明 )

    文章目录 一.重复有序拆分 二.不重复有序拆分 1.无序拆分基本模型 2.全排列 三.重复有序拆分方案数证明 参考博客 : 按照顺序看 [组合数学]生成函数 简要介绍 ( 生成函数定义 | 牛顿二项式 ...

最新文章

  1. 年度重磅发布:《人工智能发展报告2020》
  2. 2022年度BCI奖 |THE ANNUAL BCI AWARD
  3. HighNewTech之5G网络:带你了解5G网络的前世今生—两张长图帮你捋清思路
  4. 基于android的条码识别技术,基于Android手机的条码识别系统研究
  5. websockets_使用Java WebSockets,JSR 356和JSON映射到POJO的
  6. C语言void关键字
  7. ubuntu lamp(apache+mysql+php) 环境搭建及相关扩展更新
  8. 纯粹经济学 —— 基本概念
  9. 计算机基础(九):C语言基础知识小结
  10. 创建Spring项目没有Spring Config文件怎么办
  11. Springboot——quartz简单配置和使用
  12. abb机器人编程指令写字_ABB机器人编程指令与函数
  13. 一元三次方程重根判别式_一元三次方程的判别式和求根公式是什么?
  14. 沧海云帆服务器哪里的,11月沧海云帆大区天涯合璧-数据互通(合服)服务器维护公告(已完成)...
  15. python爬虫scrapy爬取新闻标题及链接_python爬虫框架scrapy爬取梅花网资讯信息
  16. Elastic 许可更新
  17. 未来智能家居24小时
  18. 中兴通讯股份有限公司薪酬待遇福利
  19. Dataset - DeepFashion 服装数据集
  20. grabcad无法注册也能下载模型的方法

热门文章

  1. ServletContextListener 启动SPRING加载数据到缓存的应用
  2. 【转】Monkey测试3——Monkey测试结果分析
  3. (剑指Offer)面试题37:两个链表的第一个公共结点
  4. Android使用AsyncTask设置请求超时的注意事项
  5. 排序----在线性时间内排序
  6. 使用脚本开启客户端远程桌面
  7. 运用.NET Framework中的类来创建看上去很专业的报表。
  8. Unity 使物体朝向某个方位
  9. 二叉树 --5.1.3 Binary Tree Zigzag Level Order Traversal --图解
  10. bootstrap table列宽设置无效解决