hdu 2031 杨辉三角
题意:显示杨辉三角形。
解法:
组合数学公式: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 杨辉三角的更多相关文章
- HDU 2032 杨辉三角
http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description 还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考 ...
- hdu 5698(杨辉三角的性质+逆元)
---恢复内容开始--- 瞬间移动 Accepts: 1018 Submissions: 3620 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- <hdu-2032>杨辉三角
这是杭电hdu上杨辉三角的链接:http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description: 还记得中学时候学过的杨辉三角吗 ...
- HDU 6129 Just do it(杨辉三角)
http://acm.hdu.edu.cn/showproblem.php?pid=6129 题意: 给出数组a,并且bi=a1^a2^a3...^ai,并且现在会重复m次,求出最后的b数组. 思路: ...
- 2014多校第六场 1007 || HDU 4927 Series 1(杨辉三角组合数)
题目链接 题意 : n个数,每操作一次就变成n-1个数,最后变成一个数,输出这个数,操作是指后一个数减前一个数得到的数写下来. 思路 : 找出几个数,算得时候先不要算出来,用式子代替,例如: 1 2 ...
- HDOJ(HDU) 1799 循环多少次?(另类杨辉三角)
Problem Description 我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次 ...
- 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 ...
- HDU 5794 A Simple Chess(杨辉三角+容斥原理+Lucas定理)
题目链接 A Simple Chess 打表发现这其实是一个杨辉三角…… 然后发现很多格子上方案数都是0 对于那写可能可以到达的点(先不考虑障碍点),我们先叫做有效的点 对于那些障碍,如果不在有效点上 ...
- hdu 2032 一维数组实现杨辉三角
杨辉三角 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- Bootstrap系列 -- 6. 列表
一. 普通无序列表 <ul> <li>无序列表项目</li> <li>无序列表项目</li> <li>无序列表项目</li ...
- [CF #236 (Div. 2) E] Strictly Positive Matrix(强联通分量)
题目:http://codeforces.com/contest/402/problem/E 题意:给你一个矩阵a,判断是否存在k,使得a^k这个矩阵全部元素都大于0 分析:把矩阵当作01矩阵,超过1 ...
- nginx安装(1) – ttlsa教程系列之nginx
1.必要软件准备 安装pcre 为了支持rewrite功能,我们需要安装pcre 1 # yum install pcre* //如过你已经装了,请跳过这一步 安装openssl 需要ssl的支持 ...
- AndroidStudio修改项目名称
项目名称修改了,想修改Android Studio 中 project的名字 右键project 的名字,refactor - rename ,填写好新名字后修改,被提示 “can’t rename ...
- iOS开发小技巧--TableView Group样式中控制每个section之间的距离
一.TableView的Group样式中,默认的每个section都有sectionHeader和sectionFooter,只要调整这两个的大小就可以实现section之前的间距扩大或缩小 二.项目 ...
- 【POJ 1743】Musical Theme
后缀数组求了height,模板题啦啦啦 #include<cstdio> #include<cstring> #include<algorithm> using n ...
- jQuery常用的元素查找方法总结
$("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("di ...
- 求割点 poj 1523
给你一些双向边 求有多少个割点 并输出去掉点这个点 去掉后有几个联通分量 Tarjan #include<stdio.h> #include<algorithm> #inclu ...
- spoj705 后缀数组求不同子串的个数
http://www.spoj.com/problems/SUBST1/en/ 题目链接 SUBST1 - New Distinct Substrings no tags Given a stri ...
- 系统间通信(3)——IO通信模型和JAVA实践 上篇
来源:http://blog.csdn.net/yinwenjie 1.全文提要 系统间通信本来是一个很大的概念,我们首先重通信模型开始讲解.在理解了四种通信模型的工作特点和区别后,对于我们后文介绍搭 ...