It is limited, at the problem is not the solution, a lot of understanding
Thank you for watching this konjac
topic:
Tournament rankings
(rank.cpp/in/out 1s 128M)
N classmates participate in the competition, asked how many kinds of rankings, allowing parallel situation
Input
Enter a number N , N <= 12 is
Output
How many kinds of output ranking
Sample Input
2
Sample Output
3
HINT
Set two students for the A, B, the following three rankings
1: A first, B second
2: A second, B first
3: A, B parallel to the first
f (i) represents the i th students to participate in competitions, and asked how many kinds of rankings, allowing parallel situation
Can be considered under the first few people, a person can have, as the result c (n, 1) * f (n-1) because a person has been removed
There may be two individual, the result is c (n, 2) * f (n-2) since it has been removed 2
There may be three individuals, then the result is c (n, 3) * f (n-3) because it has been removed 3
……
You can have n individuals, then the result is c (n, n) * f (0) is removed n al
ans is equal to the sum of the above circumstances
code:
1 #include<bits/stdc++.h> 2 using namespace std; 3 long long a[210]; 4 long long C(long long m,long long n)//C (m中取n) 5 { 6 long long ans=1; 7 for(long long i=1;i<=n;i++) 8 ans=ans*(m-i+1)/i; 9 return ans; 10 } 11 signed main() 12 { 13 long long n,t; 14 scanf("%lld",&n); 15 a[1]=a[0]=1; 16 for(long long k=2;k<=n;k++) 17 { 18 for(long long i=1;i<=k;i++) 19 { 20 a[k]+=a[k-i]*C(k,i); 21 } 22 } 23 printf("%lld\n",a[n]); 24 return 0; 25 }