zoukankan      html  css  js  c++  java
  • HDU1799——循环多少次(组合排列问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1799

    题目大意是有m层循环操作,有n次op操作,然后问下总共运行了多少次op操作。

    具体的解题思路是:使用2维数组来储存杨辉三角,然后在每次输入m,n时只需找到相应的数组就行了

    代码如下:

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <iostream>
     4 
     5 using namespace std;
     6 
     7 int list[2001][2001];//存放杨辉三角
     8 
     9 void min()
    10 {
    11     memset(list,0,sizeof(list));
    12     for (int i=0;i<=2000;i++)
    13     {
    14         list[i][0]=1;
    15         for (int j=1;j<=i;j++)
    16         {
    17             list[i][j]=list[i-1][j-1]%1007+list[i-1][j]%1007;//防止数值超过int范围
    18         }
    19     }
    20     return;
    21 }
    22 
    23 
    24 int main()
    25 {
    26     int t;
    27     int m,n;
    28     min();
    29     while (scanf("%d",&t)!=EOF)
    30     {
    31         for (int i=0;i<t;i++)
    32         {
    33             scanf("%d%d",&m,&n);
    34             printf("%d\n",list[n][m]%1007);//因为已经用memset初始化了,所以对于m>n情况结果会是0
    35         }
    36         return 0;
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    响应式布局
    CSS3过渡
    CSS3背景
    CSS渐变
    CSS3选择器
    CSS3
    自定义指令
    键盘修饰符
    过滤器
    v-if与v-show区别
  • 原文地址:https://www.cnblogs.com/shadervio/p/5730653.html
Copyright © 2011-2022 走看看