zoukankan      html  css  js  c++  java
  • 第一轮 I

    K-based Numbers
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
    Submit Status
    
    Description
    Let’s consider K-based numbers, containing exactly N digits. We define a number to be valid if its K-based notation doesn’t contain two successive zeros. For example:
    
        1010230 is a valid 7-digit number;
        1000198 is not a valid number;
        0001235 is not a 7-digit number, it is a 4-digit number. 
    
    Given two numbers N and K, you are to calculate an amount of valid K based numbers, containing N digits.
    You may assume that 2 ≤ K ≤ 10; N ≥ 2; N + K ≤ 18.
    
    Input
    The numbers N and K in decimal notation separated by the line break.
    
    Output
    The result in decimal notation.
    
    Sample Input
    input	output
    
    2
    10
    
    	
    
    90
    
    /*************************************************************************
    	> File Name: i.cpp
    	> Author:yuan 
    	> Mail: 
    	> Created Time: 2014年11月09日 星期日 21时52分04秒
     ************************************************************************/
    
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    long long ans[2][20];
    int n,k;
    int main()
    {
            cin>>n>>k;
            memset(ans,0,sizeof(ans));
            ans[0][1]=0;ans[1][1]=k-1;/*分别指定了长度为1,末尾数字为0的个数为0,不为的个数为k-1*/
            for(int i=2;i<=n;i++)
            {
                ans[0][i]=ans[1][i-1];/*不能出现连续的0,则长度为n末尾为0的个数等于长度为n-1末尾不为0的个数*/
                ans[1][i]=(k-1)*(ans[0][i-1]+ans[1][i-1]);/*长度为n,末尾数字不为0的个数:末尾数字可以是1—k-1中的任意一个
                倒数第二位可以为0,也可以不为0*/
            }
            cout<<ans[0][n]+ans[1][n]<<endl;
        return 0;
    }
    
    
    


  • 相关阅读:
    kafka管理器kafka-manager部署安装
    kafka消息监控-KafkaOffsetMonitor
    在Kafka中修改Topic的preferred replica
    kafka中对一个topic增加replicas
    在kafka上对topic新增partition
    kafka log4j配置
    kafka安装与使用
    kafka 消息服务
    软件工程期末考试复习(一)
    PM2自动发布本地项目到服务器
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254398.html
Copyright © 2011-2022 走看看