1 /* 2 Name:nyoj-451-光棍节的快乐 3 Copyright: 4 Author: 5 Date: 2018/4/25 16:44:47 6 Description:D(n)=(n-1)*(D(n-1)*D(n-2))[D[0]=0;D[1]=1] 7 */ 8 #include <iostream> 9 #include <cstdio> 10 using namespace std; 11 long long c[21][21], wrongsort[21]; 12 13 int main() 14 { 15 for (int i=1; i<=20; i++) {//阶乘打表 16 c[i][0] = c[i][i] = 1; 17 for (int j=1; j<i; j++) { 18 c[i][j] = c[i-1][j] + c[i-1][j-1]; 19 } 20 } 21 wrongsort[1] = 0; 22 wrongsort[2] = 1; 23 for (int i=3; i<=20; i++) {//错排打表 24 wrongsort[i] = (i-1) * (wrongsort[i-1] + wrongsort[i-2]); 25 } 26 int n,m; 27 while (cin>>n>>m) { 28 cout<<c[n][n-m]*wrongsort[m]<<endl; 29 } 30 return 0; 31 }
nyoj-451-光棍节的快乐(错排公式)
猜你喜欢
转载自www.cnblogs.com/evidd/p/8945855.html
今日推荐
周排行