4种不同的汽车,有2n-2个停车位,要求恰有n辆相同的车排在一起,问有多少种停车方案
分类讨论:1)n辆车在停车场两端,方案数为2*4*3*4^(n-3),
2)n辆车不在两端,方案为4*(n-3)3*3*4^(n-4),
所以总的停车方案有 24*4^(n-3)+36(n-3)*4^(n-4)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
LL mod_pow(LL x,LL n){
LL res = 1;
while(n>0){
if(n&1)res=res*x;
x=x*x;
n>>=1;
}
return res;
}
int main()
{
LL n;
cin>>n;
cout<<24*mod_pow(4,n-3)+36*(n-3)*mod_pow(4,n-4)<<endl;
return 0;
}