1. Title Description: Click to open the link
2. Solving ideas: The problem is solved by looking for a recursive relationship. The final answer is F (n). Assuming that the first person has I, there is C (n,i) possible, then there is the possibility of f (n-i). The final answer is ∑c (n,i) F (n-i) (I starting from 1).
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 1000+10#define MOD 10056int c[n ][n];int f[n];int n;void init () {c[0][0] = f[0] = 1;for (int i = 1; i <=; i++) {c[i][0] = c[i][i]=1;f[i] = 0;for (in T j = 1; J < I; J + +) C[i][j] = (C[i-1][j-1] + c[i-1][j])%mod;for (int j = 1; J <= I; j + +) F[i] = (F[i] + c[i][j] * f[i-j]%mod)% MOD;}} int main () {freopen ("test.txt", "R", stdin), int cnt = 0;init (), int t;cin >> t;while (t--) {cin >> n;printf ("case %d: ", ++cnt); cout << f[n] << Endl;} return 0;}
Example 10-14 Contest ranking UVa12034