Problem Turn the Pokers (HDU 4869)
Main topic
There are m cards, all face up. Do n operations, each time can be any AI Zhang side, ask the N operations possible number of States.
Analysis of Problem solving
Note the face up is 1, facing down is 0.
If there is a final X 1, the contribution to the answer is C (n,x). So you just need to know the number of the last possible 1.
Assuming that there is already a 1, a certain operation can be the opposite of the B card, you can find the number of possible 1 after the operation of the difference of 2.
Record the number of 1 after each operation of the interval is [L, R], can be taken to the number of L, l+2, L+4, ..., R.
Each transfer classification discussion, greedy transfer can be.
Reference Program
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 7 #defineN 1000088 #defineMo 10000000099 intA[n];Ten intPa[n],pb[n]; One intn,m; A - voidCalcint&l,int&r,intx) { - intLL,RR; the if(x<l) ll=l-x; - if(l<=x && x<=r) ll= (r-x) &1; - if(r<x) ll=x-R; - + if(x<m-r) rr=x+R; - if(m-r<=x && x<=m-l) rr=m-((m-l-x) &1); + if(m-l<x) rr=m-(x (M-l)); AL=ll; R=RR; at } - - intCintXinty) { - return1ll*pa[x]*pb[y]% Mo *pb[x-y]%mo; - } - in intQuick_pow (intXinty) { - intres=1; to while(y) { + if(y&1) Res=1ll*res*x%mo; -X=1ll*x*x%mo; theY=y >>1; * } $ returnRes;Panax Notoginseng } - the intMain () { +pa[0]=pb[0]=1; A for(intI=1; i<n;i++) pa[i]= (1ll*pa[i-1]*i)%mo; the for(intI=1; i<n;i++) Pb[i]=quick_pow (pa[i],mo-2); + while(~SCANF ("%d%d",&n,&m)) { - for(intI=1; i<=n;i++) scanf ("%d",&a[i]); $ intL=0, r=0; $ for(intI=1; i<=n;i++) Calc (l,r,a[i]); - - Long Longans=0; the for(inti=l;i<=r;i+=2) ans= (Ans+c (m,i))%mo; -printf"%i64d\n", ans);Wuyi } the}
View Code
HDU 4869 (recursive combination number modulo)