HDU 2032 杨辉三角(DP)
来源:互联网 发布:帝国cms网址导航模板 编辑:程序博客网 时间:2024/05/19 06:51
杨辉三角
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 54789 Accepted Submission(s): 22741
Problem Description
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Input
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
Output
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
Sample Input
2 3
Sample Output
11 111 11 2 1
Author
lcy
AC代码:
#include<iostream>#include<cstdlib>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<cstdlib>#include<iomanip>#include<algorithm>typedef long long LL;using namespace std;int main(){int a[500][500]; int i=0,j=0,n; while(cin>>n) { for(i=0;i<n;i++) for(j=0;j<i+1;j++) if(j==0||j==i+1) a[i][j]=1; else a[i][j]=(a[i-1][j-1]+a[i-1][j]); for(i=0;i<n;i++) { for(j=0;j<i;j++) cout<<a[i][j]<<" "; cout<<a[i][j]; cout<<endl; }cout<<endl;} return 0;}
1 0
- HDU 2032 杨辉三角(dp)
- HDU 2032 杨辉三角(DP)
- hdu 2032 杨辉三角 (java)
- hdu 2032 杨辉三角
- HDU 2032 - 杨辉三角
- HDU-2032-杨辉三角
- [hdu 2032] 杨辉三角
- HDU 2032 杨辉三角
- HDU 2032 杨辉三角
- hdu 2032 杨辉三角
- hdu-2032-杨辉三角
- HDU 2032 杨辉三角
- hdu 2032 杨辉三角
- HDU 2032 -- 杨辉三角
- HDU 2032 杨辉三角
- HDU 2032 杨辉三角
- HDU 2032 杨辉三角
- HDU 2032 杨辉三角
- mysql 优化
- 重构:Extract Method
- 剑指offer:扑克牌顺子
- 217.[Leetcode]Contains Duplicate
- 程序设计竞赛入门
- HDU 2032 杨辉三角(DP)
- 如何为Adobe Reader加入自己的书签
- 跨语言情感分析(中/英)
- Android五子连珠
- 51Nod 1202 子序列个数(简单计数dp)
- linux内核模块开发基础
- 放在ViewPager中的Button有左右滑动冲突的奇葩问题
- 169.[LeetCode]Majority Element
- centos7下添加常用YUM源(EPEL/Remi/RPMforge/php/Nginx)