https://vjudge.net/problem/UVA-10328
Test instructions
There are two characters for H and T, and now the string to be lined with n bits, the number of consecutive schemes with a minimum of K characters is asked.
Ideas:
This question and ZOJ3747 is similar, the concrete method may refer to another blog http://www.cnblogs.com/zyb993963526/p/7203833.html
But this topic is to use large numbers to do, C + + feel not very good to write, learned the next Java practice.
1 ImportJava.math.BigInteger;2 ImportJava.util.Scanner;3 4 Public classmain{5 Public Static intN;6 Public StaticBigInteger d[][]=NewBiginteger[105][2];7 8 Public StaticBigInteger Compute (intu) {9D[0][0]=biginteger.valueof (0);TenD[0][1]=biginteger.valueof (1); One for(inti=1;i<=n;i++){ ABigInteger sum = D[i-1][0].add (d[i-1][1]); -d[i][1]=sum; - the if(i<=u) d[i][0]=sum; - Else if(i==u+1) D[i][0]=sum.subtract (biginteger.valueof (1)); - ElseD[i][0]=sum.subtract (d[i-u-1][1]); - } + returnD[n][0].add (d[n][1]); - } + A Public Static voidMain (string[] args) { at intK; -Scanner in=NewScanner (system.in); - while(In.hasnext ()) { -n=in.nextint (); -k=in.nextint (); -SYSTEM.OUT.PRINTLN (Compute (n). Subtract (Compute (k-1))); in } - in.close (); to } +}
UVa 10328 Coin Toss (Java large number + recursion)