hdu 1480 钥匙计数之二

#include 
#include 

int com(int x,int y) {
    int i,up = 1,down = 1;
    for (i=1;i<=x;i++) {
        up *= i;
    }
    for (i=1;i<=y;i++) {
        down *= i;
    }
    for (i=x-y;i>0;i--) {
        down *= i;
    }
    return up/down;
}

int main() {
    int n,i,j;
    __int64 a[26],b[26],temp = 0;//b[i]是以16结尾的钥匙 
    a[2] = 0;
    a[3] = 104;
    b[2] = 0;
    b[3] = 32;
    for (i = 4;i < 26;i ++) {
        a[i] = a[i-1] * 4;//n-1是钥匙,加上2345是钥匙 
        temp = a[i-1] * 2 - b[i-1]; //n-1是钥匙,加上16是钥匙 
        a[i] += 4 * (com(3,2)+com(3,1)*2)*((__int64)pow(2,i-1)-2);//n-1不是钥匙,加上2345是钥匙  
        temp += 2 * (com(4,2)*((__int64)pow(2,i-1)-2)+4*((__int64)pow(2,i-2)-1));//n-1不是钥匙,加上16是钥匙 
        a[i] += temp;
        b[i] = temp;
    }
    for (i = 3;i < 26;i ++) {
        printf("N=%d: %I64d\n",i,a[i]);
    }

    return 0;
}

你可能感兴趣的:(acm)