HDU 2045 is not an easy series (3)-Lele's RPG puzzle

Source: Internet
Author: User
Not easy series (3)-Lele's RPG puzzle

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 23277 accepted submission (s): 9231

Problem description: Lele, the super idol of "the killer of the AC female", suddenly played Deep recently, which can lead to a lot of "Cole" (Lele fans, "Cola "), after many probing, a senior Cole finally learned the cause. It turns out that Lele has recently studied the famous RPG puzzle:

There are n squares arranged in a row, and each grid is painted in red, pink, and green, it is required that any adjacent square cannot be of the same color, and the first and last two cells are also different colors. evaluate all the methods that meet the requirements.

The above is the famous RPG puzzle.

If you are Cole, I think you will definitely try your best to help Lele solve this problem. If not, you will not stand by if you look at the faces of many beautiful Cole women who are not ready to live?

The input data contains multiple test instances. Each test instance occupies one row and is composed of an integer of N (0 <n <= 50 ).

Output for each test instance, please output all the methods that meet the requirements, each instance output occupies a line.

Sample Input

12

Sample output

36
import java.math.BigInteger;import java.util.*;public class Main {    public static void main(String[] args) {        Scanner sc=new Scanner(System.in);        while(sc.hasNextInt()){            int m=sc.nextInt();            BigInteger a[]=new BigInteger[50];            a[0]=BigInteger.valueOf(3);            a[1]=BigInteger.valueOf(6);            a[2]=BigInteger.valueOf(6);            if(m==1) System.out.println("3");            else if(m==2)System.out.println("6");            else if(m==3) System.out.println("6");            else{                                for(int i=3;i<m;i++){                    a[i]=a[i-1].add(BigInteger.valueOf(2).multiply(a[i-2]));                }                System.out.println(a[m-1]);            }        }    }}

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.