2016huasacm暑假集训训练四 递推_A

题目链接:https://vjudge.net/contest/125308#problem/A

这题主要考的就是就是一个排列公式,但是不能用阶乘的公式,    用这个公式不易超时 a[i][j] = a[i - 1][j] + a[i - 1][j - 1];另外这个公式也可以求杨辉三角

AC代码:

 1  
 2 #include<stdio.h>
 3 int a[2001][2001];
 4 void C()
 5 {
 6     for(int i= 1; i<= 2000; i++)
 7     {
 8          a[0][0] = 1;
 9          a[i][0] = 1;
10         for(int j=1; j<= 2000; j++)
11             a[i][j] = (a[i - 1][j]%1007 + a[i - 1][j - 1]%1007)%1007;
12             }
13 }
14 int main()
15 {
16     int t, x, y;
17     C();
18     scanf("%d", &t);
19     while(t--)
20     {
21         scanf("%d%d", &y, &x);
22         printf("%d
", a[x][y]);
23         }
24     
25     return 0;
26 }
原文地址:https://www.cnblogs.com/LIUWEI123/p/5743485.html