POJ 1942
开始时竟然用了分情况讨论。
仔细思考一下,哈哈,发现不过是多重集合的组合数而已。
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std;
typedef __int64 u_int; u_int myc(u_int n,u_int r){
u_int sum=1;
for(u_int i=1;i<=r;i++)
sum=sum*(n+1-i)/i;
return sum;
} int main(){
u_int n,m;
while(scanf("%I64d%I64d",&n,&m),m||n){
if(n>m){
u_int tmp=m;
m=n;
n=tmp;
}
u_int s=m+n;
u_int t=s%2?s/2+1:s/2;
n=n>t?s-t:n;
u_int sum=myc(s,n);
printf("%I64d\n",sum);
}
return 0;
}
POJ 1942的更多相关文章
- POJ 1942 Paths on a Grid(组合数)
http://poj.org/problem?id=1942 题意 :在一个n*m的矩形上有n*m个网格,从左下角的网格划到右上角的网格,沿着边画,只能向上或向右走,问有多少条不重复的路 . 思路 : ...
- Paths on a Grid(poj 1942)
给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走. //注意循环的时候,要循环小的数,否 ...
- POJ 1942 Paths on a Grid
// n*m 的格子 从左下角走到右上角的种数// 相当于从 n+m 的步数中选 m 步往上走// C(n+m,m) #include <iostream> #include <st ...
- Paths on a Grid POJ - 1942 组合数学 (组合数的快速计算)
题意:格路问题 没什么难度 难点在于如何快速计算相对较大的组合数 思路:运用手写计算组合数的方式进行计算 如c(8,3) 如果手算就是 8*7*6/(3*2*1)这样可以很快得解出 计算代码为: ...
- POJ - 1942 D - Paths on a Grid
Imagine you are attending your math lesson at school. Once again, you are bored because your teacher ...
- [ACM] POJ 1942 Paths on a Grid (组合)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21297 Accepted: 5212 ...
- POJ 1942:Paths on a Grid
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22918 Accepted: 5651 ...
- Paths on a Grid POJ - 1942 排列组合
题意: 从左下角移动到右上角.每次只能向上或者向右移动一格.问移动的轨迹形成的右半边图形有多少种 题解: 注意,这个图形就根本不会重复,那就是n*m的图形,向上移动n次,向右移动m次. 从左下角移动到 ...
- poj很好很有层次感(转)
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...
随机推荐
- 由free命令想到的
root@xdj-Z9PA-D8-Series:~# free -m total used free shared buffers cached Mem: 15977 1683 14293 0 132 ...
- 《编程导论(Java)·7.4.4 String对象问题》
String是Java API中使用频率第一的类,曾经在CSDN论坛上.至少每一个月都有相关的贴子,讨论==和equals(). 本节介绍这一部分的内容,也有一个重要更正. String文字在程序中被 ...
- hdu5386 Cover
Problem Description You have an n∗n matrix.Every grid has a color.Now there are two types of operati ...
- Shiro 学习应用(续)
在前面的文章中为大家介绍了 Shrio 的基础概念.可能比較笼统.没有深入到开发过程的一些问题.如今集中在本帖中归纳一下有关问题. FormAuthenticationFilter 表单过滤器 表单过 ...
- ASP.NET六大巨头——内置对象(1)
ASP.NET提供了六个内置对象:Request.Response.Application.Session.Server和Cookie.这些对象收集当前应用程序请求.用户信息.响应浏览器信息,来完毕页 ...
- idea 中web项目 用自带tomcat启动问题,
严重: Exception sending context initialized event to listener instance of class com.zenointel.logserve ...
- CountDownTimer,0,0
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); s ...
- [Swift]二进制、八进制、十进制、十六进制之间的转换
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Python—JSON数据解析
1.安装pip pip是python的包管理工具,使用它能非常方便地安装和卸载各种python工具包 第一步:直接用浏览器访问地址:https://raw.github.com/pypa/pip/ma ...
- 获取sqlserver数据字典的完整sql。
SELECTsysobjects.name AS 表名称 , --------------as 的作用:为字段起一个别名 --sysproperties.[value] AS 表说明 , ------ ...