Title: Express Small Brother every day is fortunate to send courier, today he needs to send n a courier to n a recipient, the first express need to send to the first recipient, I would like to ask which happened exactly K sent the wrong number of cases is how much?
Input: Multiple examples, two numbers per line N and K,1<<n<<1000,0<<k<<n, two are 0 end, the sample does not need to be processed.
Output: Each line outputs a result, because the values are larger, so all results require a 10^9+7 modulo.
Analysis: Water problem
1, using the wrong row formula to calculate exactly K of the number of rows of the wrong, pre-processing an array.
2, from the N medium remove K have C (n,k) species.
3, C (n,k) and f[k] are multiplied to the final result.
Code:
#include <iostream>using namespace Std;__int64 f[1005];void Init () {f[0]=0;f[1]=0;f[2]=1;for (int i=3;i<=1001 ; i++) f[i]= ((i-1) * ((F[i-1]+f[i-2])%1000000007)%1000000007;} __int64 CNK (int n,int k) {__int64 a,b;int i;a=b=1;for (i=k+1;i<=n;i++) a*=i;for (i=2;i<=n-k;i++) B*=i;return A/b;} int main () {int n,k;init (); while (cin>>n>>k && (n| | k) {printf ("%i64d\n", (CNK (n,k) *f[k])%1000000007);} return 0;}
A disguised version of the wrong-line formula-Express delivery