题目链接: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 }