题意:显示杨辉三角形。

解法:

组合数学公式: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. FFmpeg 1.2 for Android 生成一个动态库

    上一篇<FFmpeg 1.2 for Android 编译动态库>里沃特跟大家介绍了如何编译动态库,但当时所生成的动态库总共包含10个so文件,这样要是加载起来会严重影响软件的启动速度,后 ...

  2. 仿造slither.io第一步:先画条蛇

    前言 最近 slither.io 貌似特别火,中午的时候,同事们都在玩,包括我自己也是玩的不亦乐乎. 好久好久没折腾过canvas相关的我也是觉得是时候再折腾一番啦,所以就试着仿造一下吧.楼主也没写过 ...

  3. Xamarin Android -创建Splash Screen (一)

    ......(空话少说) Xamarin 开发的技术资料很少,通过学习,把自己的学习过程及其中碰到的问题与大家分享. Splash Screen 就是在应用程序启动时,出现的一张图片,一般App的Sp ...

  4. 删除root子目录,如何恢复子目录配置文件

    手贱,一不小心rm -rf 问题描述:删除/root/子目录文件(含隐藏配置文件)shell变成-bash-4.2#,如何恢复原貌 解决方法: root用户进入,自己配置相关文件:mkdir /roo ...

  5. Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo

    更新了xcode后使用goland运行项目时提示 Agreeing to the Xcode/iOS license requires admin privileges, please re-run ...

  6. SharePoint Web Part Error – The Specified Solution Was Not Found

    If you develop, release and add a SharePoint 2010 sandboxed solution web part to a page, then change ...

  7. Java文件拷贝

    package com.lxm.demos; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io. ...

  8. java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 错误

    你的ArrayList 是一个没有值的对象(不是null),也就是里面什么对象也没有存(即:arrayList.size()==0).但是,你有取它下标为0值的操作.所以,数组越界了!!比如array ...

  9. Region-Based Segmentation

    读完10.4 Region-Based Segmentation这一小节, 新get到的且需要留意的知识点: Region Spltting and Merging, quadtrees Waters ...

  10. Swift 高阶函数

    map.flatMap.filter和reduce,几乎实现lambda表达式的语言里都会在集合里增加这些方法, 见swift 学习(一)基础知识 (基本数据类型,操作符,流控制,集合)中的集合 ht ...