钥匙计数之二
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1019 Accepted Submission(s): 579
Problem Description
一把钥匙有N个槽,2<N<26槽深为1,2,3,4,5,6。每钥匙至少有3个不同的深度且相连的槽其深度之差不得为5。求这样的钥匙的总数。
Input
本题无输入
Output
对2<N<26,输出满足要求的钥匙的总数。
Sample Output
N=3: 104 N=4: 904 N=5: 5880 . . . . . N=25: 8310566473196300280
Source
Recommend
lcy | We have carefully selected several similar problems for you:
1438
1465
1297
1466
2050
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <limits.h>
using namespace std;
int main()
{
long long a[30];
long long b[30]; ///end of 1 6
long long c[30]; ///end of 2 3 4 5
int i;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
a[3]=104;
c[3]=72;
b[3]=32;
for(i=4; i<=25; ++i)
{
/// n-1未构成钥匙
b[i]+=2*(6*(pow(2,i-1)-2)+4*(pow(2,i-2)-1));
c[i]+=36*(pow(2,i-1)-2);
/// n-1已构成钥匙
c[i]+=4*a[i-1];
b[i]+=c[i-1]*2+b[i-1];
a[i]+=b[i]+c[i];
}
for(i=3; i<=25; i++)
cout<<"N="<<i<<": "<<a[i]<<endl;
return 0;
}