题意:显示杨辉三角形。

解法:

组合数学公式:combi(n,m)=combi(n-1,m-1)+combi(n-1,m);

至于为什么有这个公式呢?那就是高中数学的内容啦

   1:  #include<stdlib.h>
   2:  #include<string.h>
   3:  #include<stdio.h>
   4:  #define N 31
   5:  int map[N][N];
   6:  void init(){
   7:      int i,j;
   8:      memset(map,0,sizeof(map));
   9:      map[0][0]=1;
  10:      for(i=1;i<N;i++){
  11:          for(j=1;j<=i;j++){
  12:              map[i][j]=map[i-1][j-1]+map[i-1][j];  //关键代码
  13:          }
  14:      }
  15:  }
  16:  int main(){
  17:      int n,i,j,cnt=0;
  18:      init();
  19:      while(scanf("%d",&n)!=EOF){
  20:          cnt++;
  21:          
  22:          for(i=1;i<=n;i++){
  23:              for(j=1;j<=i;j++){
  24:                  if(j!=1) printf(" ");
  25:                  printf("%d",map[i][j]);
  26:              }
  27:              printf("\n");
  28:          }
  29:          printf("\n");
  30:      }
  31:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

hdu 2031 杨辉三角的更多相关文章

  1. HDU 2032 杨辉三角

    http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description 还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考 ...

  2. hdu 5698(杨辉三角的性质+逆元)

    ---恢复内容开始--- 瞬间移动 Accepts: 1018 Submissions: 3620 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...

  3. <hdu-2032>杨辉三角

    这是杭电hdu上杨辉三角的链接:http://acm.hdu.edu.cn/showproblem.php?pid=2032  Problem Description: 还记得中学时候学过的杨辉三角吗 ...

  4. HDU 6129 Just do it(杨辉三角)

    http://acm.hdu.edu.cn/showproblem.php?pid=6129 题意: 给出数组a,并且bi=a1^a2^a3...^ai,并且现在会重复m次,求出最后的b数组. 思路: ...

  5. 2014多校第六场 1007 || HDU 4927 Series 1(杨辉三角组合数)

    题目链接 题意 : n个数,每操作一次就变成n-1个数,最后变成一个数,输出这个数,操作是指后一个数减前一个数得到的数写下来. 思路 : 找出几个数,算得时候先不要算出来,用式子代替,例如: 1 2 ...

  6. HDOJ(HDU) 1799 循环多少次?(另类杨辉三角)

    Problem Description 我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次 ...

  7. HDU - 6129 :Just do it (杨辉三角)

    There is a nonnegative integer sequence a 1...n  a1...n of length n n . HazelFan wants to do a type ...

  8. HDU 5794 A Simple Chess(杨辉三角+容斥原理+Lucas定理)

    题目链接 A Simple Chess 打表发现这其实是一个杨辉三角…… 然后发现很多格子上方案数都是0 对于那写可能可以到达的点(先不考虑障碍点),我们先叫做有效的点 对于那些障碍,如果不在有效点上 ...

  9. hdu 2032 一维数组实现杨辉三角

    杨辉三角 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

随机推荐

  1. 【算法之美】你可能想不到的归并排序的神奇应用 — leetcode 327. Count of Range Sum

    又是一道有意思的题目,Count of Range Sum.(PS:leetcode 我已经做了 190 道,欢迎围观全部题解 https://github.com/hanzichi/leetcode ...

  2. 各种主流 SQLServer 迁移到 MySQL 工具对比

          我之所以会写这篇对比文章,是因为公司新产品研发真实经历过这个痛苦过程(传统基于SQL Server开发的C/S产品转为MySQL云产品).首次需要数据转换是测试环节,当时为了快速验证新研发 ...

  3. C8051逆向电阻屏:头儿拍脑袋说电阻屏IC好赚钱3块钱成本能卖20几块。,一个月不分昼夜逆向成功后头儿说电阻屏已经被市场淘汰请放弃治疗。

    参考: 书籍,<圈圈教你玩USB>  C8051F单片机快速入门:http://www.waveshare.net/Left_Column/C8051F_Application_Notes ...

  4. fdisk分区硬盘并shell脚本自动化

    最近工作需要用到对硬盘进行shell脚本自动化分区和mount的操作,google了一些资料,下面做个总结. 如果硬盘没有进行分区(逻辑分区或者扩展分区,关于两者概念,自行google),我们将无法将 ...

  5. .Net相关

    Lucene 全文搜索 http://lucenenet.apache.org/ Memcached 分布式缓存 http://memcached.org/ selenium UI自动化测试 http ...

  6. 为什么要加入<!doctype html>这个文档声明——IE怪异模式

    调试了很久,发现了一个非常细微但又十分重要的问题,又一次我在对于文档声明类型的时候,声明了如下类型 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  7. 【Javascript】好用的js弹层插件,layerUI

    官网:layerUI 中文手册:layerAPI

  8. Learning jQuery, 4th Edition 勘误表

    来源于:http://book.learningjquery.com/3145/errata/ Chapter 1 page 14 The CSS snippet is correct, but it ...

  9. android launchmode(四种启动模式)应用场景及实例

    模式介绍 [1] standard 模式 这是默认模式,每次激活Activity时都会创建Activity实例,并放入任务栈中. [2] singleTop 模式 如果在任务的栈顶正好存在该Activ ...

  10. android -- 之PopupWindow的使用

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View contentVi ...