• AOJ 162.杨辉三角


    Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
    Total Submission: 47   Submission Accepted: 26
     
    Description
    1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1
    1 5 10 10 5 1
    上面的图形熟悉吗?它就是我们中学时候学过的杨辉三角。
    现在请你输出一个m层的杨辉三角
    Input
    输入包含n组数据
    行1至行n:一个正整数m,m∈[1,30]
    行n+1:一个整数0,代表输入结束
    Output
    对应于每一个输入,请输出相应层数的杨辉三角
    每一层的整数之间用一个空格隔开
    每一个杨辉三角后面加一个空行
    Sample Input
    Original Transformed
    2
    3
    0
    
    Sample Output
    Original Transformed
    1
    1 1
    
    1
    1 1
    1 2 1
    

    动态规划

    s[i][j]=s[i-1][j]+s[i-1][j-1]

    不过数据只有30组,可以采用打表法

     1 /*
     2 By:OhYee
     3 Github:OhYee
     4 Email:oyohyee@oyohyee.com
     5 */
     6 #include <cstdio>
     7 #include <algorithm>
     8 #include <cstring>
     9 #include <cmath>
    10 #include <string>
    11 #include <iostream>
    12 #include <vector>
    13 #include <list>
    14 #include <queue>
    15 #include <stack>
    16 using namespace std;
    17  
    18 #define REP(n) for(int o=0;o<n;o++)
    19  
    20 char s[30][10000] = {
    21     "1",
    22     "1 1",
    23     "1 2 1",
    24     "1 3 3 1",
    25     "1 4 6 4 1",
    26     "1 5 10 10 5 1",
    27     "1 6 15 20 15 6 1",
    28     "1 7 21 35 35 21 7 1",
    29     "1 8 28 56 70 56 28 8 1",
    30     "1 9 36 84 126 126 84 36 9 1",
    31     "1 10 45 120 210 252 210 120 45 10 1",
    32     "1 11 55 165 330 462 462 330 165 55 11 1",
    33     "1 12 66 220 495 792 924 792 495 220 66 12 1",
    34     "1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1",
    35     "1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1",
    36     "1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1",
    37     "1 16 120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820 560 120 16 1",
    38     "1 17 136 680 2380 6188 12376 19448 24310 24310 19448 12376 6188 2380 680 136 17 1",
    39     "1 18 153 816 3060 8568 18564 31824 43758 48620 43758 31824 18564 8568 3060 816 153 18 1",
    40     "1 19 171 969 3876 11628 27132 50388 75582 92378 92378 75582 50388 27132 11628 3876 969 171 19 1",
    41     "1 20 190 1140 4845 15504 38760 77520 125970 167960 184756 167960 125970 77520 38760 15504 4845 1140 190 20 1",
    42     "1 21 210 1330 5985 20349 54264 116280 203490 293930 352716 352716 293930 203490 116280 54264 20349 5985 1330 210 21 1",
    43     "1 22 231 1540 7315 26334 74613 170544 319770 497420 646646 705432 646646 497420 319770 170544 74613 26334 7315 1540 231 22 1",
    44     "1 23 253 1771 8855 33649 100947 245157 490314 817190 1144066 1352078 1352078 1144066 817190 490314 245157 100947 33649 8855 1771 253 23 1",
    45     "1 24 276 2024 10626 42504 134596 346104 735471 1307504 1961256 2496144 2704156 2496144 1961256 1307504 735471 346104 134596 42504 10626 2024 276 24 1",
    46     "1 25 300 2300 12650 53130 177100 480700 1081575 2042975 3268760 4457400 5200300 5200300 4457400 3268760 2042975 1081575 480700 177100 53130 12650 2300 300 25 1",
    47     "1 26 325 2600 14950 65780 230230 657800 1562275 3124550 5311735 7726160 9657700 10400600 9657700 7726160 5311735 3124550 1562275 657800 230230 65780 14950 2600 325 26 1",
    48     "1 27 351 2925 17550 80730 296010 888030 2220075 4686825 8436285 13037895 17383860 20058300 20058300 17383860 13037895 8436285 4686825 2220075 888030 296010 80730 17550 2925 351 27 1",
    49     "1 28 378 3276 20475 98280 376740 1184040 3108105 6906900 13123110 21474180 30421755 37442160 40116600 37442160 30421755 21474180 13123110 6906900 3108105 1184040 376740 98280 20475 3276 378 28 1",
    50     "1 29 406 3654 23751 118755 475020 1560780 4292145 10015005 20030010 34597290 51895935 67863915 77558760 77558760 67863915 51895935 34597290 20030010 10015005 4292145 1560780 475020 118755 23751 3654 406 29 1"
    51 };
    52  
    53 int main() {
    54     int m;
    55     while(scanf("%d",&m),m!=0) {
    56         for(int i = 0;i < m;i++)
    57             printf("%s
    ",s[i]);
    58         printf("
    ");
    59     }
    60  
    61     /*
    62     int s[31][31] = {0};
    63     s[0][0] = 1;
    64     for(int i = 1;i <= 30;i++) {
    65         for(int j = 1;j <= i;j++) {
    66             s[i][j] = s[i - 1][j - 1] + s[i - 1][j];
    67         }
    68     }
    69     for(int i = 1;i <= 30;i++) {
    70         printf(""");
    71         for(int j = 1;j <= i;j++) {
    72             printf("%d",s[i][j]);
    73             if(j != i)
    74                 printf(" ");
    75         }
    76         printf("",");
    77         printf("
    ");
    78     }
    79     */
    80     return 0;
    81 }
  • 相关阅读:
    java 反射 报错:Attempt to get java.lang.Integer field "..." with illegal data type conversion to int
    经常报错:Communications link failure
    解析Excel
    spring+atomikos+mybatis 多数据源事务(动态切换)
    mysql 存储过程
    Ace Admin 学习笔记
    spring mvc 表单提交 乱码
    spring 事务
    基于注解的Spring多数据源配置和使用(非事务)
    javaEE版本的eclipse中导入工程,发现server里面找不到工程,根本发布不了也不能运行
  • 原文地址:https://www.cnblogs.com/ohyee/p/5269877.html
Copyright © 2020-2023  润新知