UVa 10328 Coin Toss (Java large number + recursion)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.