codeforces 630 I Parking Lot (規律&&組合)

Parking Lot
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Input

The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make.

Output

Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.

Examples
Input
3
Output
24
Note

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.

正如題目:對排列組合應用,有n個相同的車停在一起時,此時又2*n-2個停車位!

                                                           左                                   中                                       右

             <當n==4>時                     4*3*4                             3*4*3                                  4*3*4

                           5                           4*3*4*4                  3*4*3*4+4*3*4*3                    4*4*3*4

                    (1)當n輛車停在兩端時: 左加右=2*(3*pow(4,n-2));

                    (2)當n輛車停在中間時:(n-3)*3*3*pow(4,n-3);

  ACcode

#include<stdio.h>
#include<math.h>
int main()
{
	__int64  n;
	while(scanf("%I64d",&n)!=EOF)
	{
		__int64 t1,t2;
		t1=2*3*pow(4,n-2);
		t2=(n-3)*3*3*pow(4,n-3);
		printf("%I64d\n",t1+t2);
	}
} 


發佈了263 篇原創文章 · 獲贊 67 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章