Oh, my Paper!
时间限制:1000 ms | 内存限制:65535 KB 难度:2- 描述
-
Give you a piece of paper, n (row) *m (column) to calculate your is
Calculated from a diagonal line to another diagonal how many walk method (only upward or downward, left, and right away).- 输入
- The input contains several testcases. Each is specified by two unsigned 32-bit integers n and m The last test case is followed by a line that contains two zeroes. This line must not be processe
- 输出
- For each test case output on a line that how many paths you can calculate
- 样例输入
-
2 3 1 1 0 0
- 样例输出
-
10 2
- 提示
- the num is a little big ,you'd better use unsigned
- 来源
- 原创
-
上传者
ACM_贺荣伟
思路:(直接用伟哥的)给你一张纸,n(行)*m(列)你要计算的是
算出从一个对角线到另一个对角线有多少走法(只能向上,向右走)。
分析:一个矩阵,它有行有列,要到达对角线,必定有通过所有的行和列,那么存在两种情况,当行(n)==列(m),即刚好走完列和行,在m+n个里选m或n个组合得C(m+n,m)或C(m+n,n)。
当两者不相等,就要看那个先到,所有最小的必定先到达。#include#include #include #include using namespace std; int main() { long long n,m; while(~scanf("%lld%lld",&n,&m),n||m) { long long a,b; a=n+m; b=n 0) sum*=(a--/(double)(b--)); printf("%.lf\n",sum); } }
- <script type="text/java script">BAIDU_CLB_fillSlot("771048");
- 点击复制链接 与好友分享! 回本站首页 <script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];