相当于从n-1个位置里面找k-1个位置放隔板
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 #define LL long long int 7 8 using namespace std; 9 10 int main() 11 { 12 double n, k; 13 int T; 14 scanf( "%d", &T ); 15 while ( T-- ) 16 { 17 scanf( "%lf%lf", &n, &k ); 18 if ( n - k < k - 1 ) k = n - k + 1.0; 19 double ans = 1.0; 20 for ( double i = 1; i < k; ++i ) 21 { 22 ans *= ( n - i ) / i; 23 } 24 printf( "%.0f ", ans ); 25 } 26 return 0; 27 }