原理:
实现方法
#include <iostream>using namespace std;typedef long long LL;long long c[10][10];int main() { for(int i=0;i<10;i++){ for(int j=0;j<=i;j++){ if(!j) c[i][j]=1; else c[i][j]=(c[i-1][j]+c[i-1][j-1]); // cout << c[i][j] << ' '; } // cout << endl; } for(int i=1;i<10;i++){ for(int j=1;j<=i;j++){ cout << c[i][j] << ' '; } cout << endl; } return 0;}
原题:
#include <iostream>using namespace std;typedef long long LL;const int N = 2010;LL c[N][N];const int M = 1e9 +7;void init(){ for(int i=0;i<N;i++){ for(int j=0;j<=i;j++){ if(!j) c[i][j]=1; else c[i][j]=(c[i-1][j]+c[i-1][j-1]) % M; // cout << c[i][j] << ' '; } // cout << endl; }}int main() { init(); int m, x ,y; cin >> m; while(m--){ cin >> x >> y; cout << c[x][y] << endl; } return 0;}