To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever.
Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly n successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.
The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make.
Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.
3
24
Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM
Originally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City.
题意:
有四个汽车厂生产四种汽车,问(2*n-2)个汽车排成一排时,其中有n个相同的车相连的情况有多少种
比较复杂一点的排列组合问题,需要捆绑,插孔,等等中间运算
不过只要详细理解题意,分类讨论的话,还是比较容易解决的...
#include<stdio.h>
#include<math.h>
typedef long long ll;
ll C(ll n,ll m)
{
if(m>n-m)
{
m=n-m;
}
ll ans=1;
for(ll i=0;i<m;++i)
{
ans=ans*(n-i)/(i+1);
}
return ans;
}
int main()
{
ll n;
while(~scanf("%lld",&n))
{
ll a=pow(4,n-3),b=0;
if(n>3)
{
b=a/4;
}
printf("%I64d\n",4*(2*3*a+(n-3)*9*b));
}
return 0;
}