UVA, 580 Critical Mass

Source: Internet
Author: User

Test instructions: Give you u and l string 3 consecutive U for dangerous goods, give you x length of string, to find the number of dangerous

Idea: Recursion

Number of security solutions: m[i]=m[i-1]+m[i-2]+m[i-3] Fibonacci sequence Upgrade (╯‵-′) ╯︵┻━┻

1#include <iostream>2#include <cstdio>3 using namespacestd;4 intN;5 #defineMAXN 516 Long LongM[MAXN];7 BOOLdatecin ()8 {9     if(SCANF ("%d", &n)! =EOF)Ten     { One         if(n==0) A             return false; -         return true; - }ac the     return false; - } -  - voiddatecal () + { -  +m[0]=1, m[1]=1; A      for(intI=2; i<maxn;i++) atm[i]=m[i-1]+m[i-2]; - } -  - voidshowres () - { -printf"%lld\n", M[n]); in } - intMain () to { + datecal (); -      while(Datecin ()) the     { * showres (); $     }Panax Notoginseng     return 0; -}
View Code

UVA, 580 Critical Mass

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.