Test instructions: A, a and two people race, ranking has three kinds of situation (tie first, ab,ba). Enter N to find the number of possible final positions for the individual race.
Analysis: Originally thought is the mathematics question, arranges the combination, later how to think also is not right. Turns out this is a recursive ...
The answer for the n person is f (n) assuming that the first name has I (0< i <= N) individuals, that is, C (n, I) species, and F (n-i) is possible, then easy.
F (n) =σc (n, i) f (n-i).
The code is as follows:
#include <iostream>#include<cstdio>#include<cstring>#defineMoD%10056using namespacestd;Const intMAXN =1001;intc[maxn+5][maxn+5], f[maxn+5];voidinit () { for(inti =0; i < MAXN; i++) C[i][i]=1, c[i][0] =1; for(inti =1; I <1001; i++) for(intj =1; J <= I; J + +) C[i][j]= (c[i-1][j-1] + c[i-1][j]) mod;}voidsolve () {f[0] =1, f[1] =1, f[2] =3; for(inti =3; I <1001; i++) for(intj =1; J <= I; J + +){ intK = (c[i][j]*f[i-j]) mod; F[i]= (k +f[i]) mod; }}intMain () {memset (c,0,sizeof(c)); Memset (F,0,sizeof(f)); Init (); Solve (); intN, T, cases =0; CIN >>T; while(t--) {scanf ("%d", &N); printf ("Case %d:%d\n", ++cases, f[n]); } return 0;}
UVa 12034 Race (recursive + combinatorial math)