• 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
    ",f[n]);  	
        }
    	return 0;
    }
    

      

  • 相关阅读:
    Netty入门(三)之web服务器
    Math对象
    DOM
    BOM
    字符串
    数组
    ajax
    如何安装vue脚手架
    git提交拉取远程仓库
    第九届蓝桥杯,赛后感!!含泪写完。
  • 原文地址:https://www.cnblogs.com/tonghao/p/5202153.html
Copyright © 2020-2023  润新知