Descriptioninput the 1th Act integer n (2<=n<=50) and M (0<=m<=n). The following n lines are sequentially the information from top to bottom n rows of nails, and each line ' * ' indicates that the nail is still there, '. ' Indicates that the nail is removed, note that the space character may appear anywhere in this n line. Output is only one row, which is an approximate fraction (0 written in 0/1), which is the approximate PM of a small ball in a lattice numbered m. Definition of both the fraction: A/b is both an approximate fraction when and only if A and B are positive integers and a and b do not have a public factor greater than 1. Sample Input5 2
Sample Output7/16
Solution
Set F[i][j] represents the probability of the ball falling to the position (I,J), and the fractional solution can be
#include <stdio.h>#defineL Long Long#defineRG RegisterinlinevoidRin (RGint&x) {x=0; RgintC=getchar (), f=1; for(;c< -|| C> $; c=GetChar ())if(! (c^ $)) f=-1; for(;c> -&&c< -; c=GetChar ()) x= (x<<1) + (x<<3) +c- -; X*=F;} InlinevoidPloy (RGBOOL&x) {RGCharC=GetChar (); while(c!='*'&&c!='.') c=GetChar (); X=c=='*'?true:false; }voidShiki (RG L x) {if(!x)return; Shiki (x/Ten); Putchar (x%Ten+ -); }l gcd (RG l A,RG l b) {returnB?GCD (b,a%b): A; }BOOL_map[ -][ -];intn,m;structfr{L n,d; Fr (RG L _=0, RG L __=1): N (_), D (__) {}}f[ -][ -];inlinevoidRec (FR &_this) {L T=gcd (_THIS.N,_THIS.D); _THIS.N/=T; _THIS.D/=T;} Froperator+ (ConstFr &a,ConstFr &b) {fr res; L T=gcd (A.D,B.D); RES.N=b.d/t*a.n+a.d/t*B.N; RES.D=a.d/t*B.D; returnRes;} Froperator* (ConstFr &a,ConstFr &b) {fr res (A.N*b.n,a.d*B.D); Rec (RES); returnRes;}void operator+ = (Fr &a,ConstFr &b) {a=a+b;}intMain () {rin (n), Rin (m); for(RGintI=1; i<=n; i++) for(RGintj=1; j<=i; J + +) ploy (_map[i][j]); f[1][1]=FR (1,1); for(RGintI=1; i<=n; i++) for(RGintj=1; j<=i; J + +) Rec (f[i][j]), _map[i][j]?F[i+1][J]+=F[I][J]*FR (1,2), f[i+1][j+1]+=F[I][J]*FR (1,2): F[i+2][j+1]+=F[i][j]; Rec (F[n+1][m+1]); Shiki (F[n+1][m+1].N); Putchar ('/'); Shiki (f[n+1][m+1].D); return 0;}
[bzoj1867] [Noi1999] [Nails and pellets] (Dynamic planning)