codeforces 630C Lucky Numbers

C. Lucky Numbers
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.

Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits.

Input

The only line of input contains one integer n (1 ≤ n ≤ 55) — the maximum length of a number that a door-plate can hold.

Output

Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than n digits.

Examples
input
2
output
6

 题意:所有只有7或者只有8,或者只有7和8组成的数成为幸运数,给你一个n表示最多有n位的数,现在问你在这n位数之内有多少个幸运数

题解:当n为1时幸运数是7和8当n为两位数时,两位的数中有77,78,88,87,我们可以发现,这是对7和8在n个位置上进行组合数排列n位数是

(只说n位数的幸运数个数)是c1(2,1)*c2(2,1)*...*cn(2,1)     n位数时所有的幸运数个数就是一位数是幸运数个数加上两位数时幸运数个数+...+n位数是幸运数个数   打表储存

#include<stdio.h>    //codeforce   c
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#define INF 0x3f3f3f
#define MAX 100100
#define LL long long
using namespace std;
LL f[MAX];
void biao()
{
	f[1]=2;
	f[2]=6;
	for(int i=3;i<=55;i++)
		f[i]=f[i-1]+pow(2,i);
}
int main()
{
	int i,j,n,m;
	biao();
    while(scanf("%d",&n)!=EOF)
    {
    	printf("%lld\n",f[n]);  	
    }
	return 0;
}

  

posted @ 2016-02-19 20:48  非我非非我  阅读(607)  评论(0编辑  收藏  举报