One of the key counts (recursive) hdu1438

Source: Internet
Author: User

One of the key countsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1471 Accepted Submission (s): 622


Problem description A key has n slots, Groove deep 1,2,3,4. Each key has at least 3 different depths and at least 1 pairs of connected slots have a depth difference of 3. To find the total number of such keys.
Input not in the subject
Output to n>=2 and n<=31, outputs the total number of keys that meet the requirements.
Sample Output
N=2:0N=3:8N=4:64N=5:360..............N=31: ... Note: Adapted according to PKU Judge Online 1351 number of locks or Xi ' an 2002, where n<=16


Reprint please specify the Source: Search & Star Children

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1438

/*1: If x is the key, then X1/2/3/4 is also, so a[i]=a[i-1]*42: If x is not, X2/3 is the x is composed of 1/4, but to remove all 1 and all 4, so a[i]+= (2^ (I-1) 2) * * Suffix 2 or 3 plus it becomes the key, Must be not satisfied need 3 different depth groove this one, so x must be composed of 1/4 3 if X is not X1/4 is. Then X=y (m=x1/4=y) (4/1) (1/4) The front I-2 bit can be 1234, but to remove all the cases of 1/4 is the case that X is the key and X is the end of 1/4. We use the B[i] array to represent the number of I bits ending at 1/4   temp= (4^ (i-2) -2^ (i-2)) * 2–b[i-1]; b[i]=a[i-1]*2+temp;*/#include <stdio.h># Define LL long Long#include<string.h>ll a[35],b[35]; ll Ppow (ll n,ll m) {    ll c=1;    while (m)    {        if (m&1) c=c*n;        N=n*n;        m>>=1;    }    return c;} int main () {    a[0]=a[1]=a[2]=0;    b[0]=b[1]=b[2]=0;    LL temp=0;    printf ("n=2:0\n");    for (int i=3;i<=31;i++)    {        temp= (Ppow (4,i-2)-ppow (2,i-2)) *2-b[i-1];//       printf ("temp=%lld\t", temp );        B[i]=a[i-1]*2+temp;        a[i]=a[i-1]*4+ (Ppow (2,i-1)-2) *2+temp;        printf ("n=%d:%lld\n", I,a[i]);    }    return 0;}


One of the key counts (recursive) hdu1438

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.