zoukankan      html  css  js  c++  java
  • Codeforces 1327E. Count The Blocks【数学题】

    传送门

    题意

    统计从 (00...0)(99...9)(10^n-1) 个数中出现的块长为 (1,2,...,n) 的块的个数各为多少。

    题解

    这道题不算难,昨晚没做出来实在是太蠢了,得好好反思。

    对于长度 (i) 的块,直接考虑处于不同位置时对答案的贡献。

    如果 (n=i),显然为 (f[i]=10)

    如果 (n=i+1),那么 (f[i]=10*9+9*10)

    如果 (n>i+1),那么 (f[i]=10*9*10^{n-i-1}+10*9*9*10^{n-i-2}*(n-i-2+1)+10*9*10^{n-i-1})

    代码

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #define ff first
    #define ss second
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> PII;
    const int N=3e5+10;
    const int M=1e6+10;
    const int mod=998244353;
    int n;
    LL f[N],po[N];
    
    int main(){
    	scanf("%d",&n);
    	po[0]=1;
    	for(int i=1;i<=n;i++) po[i]=po[i-1]*10%mod;
    	for(int i=1;i<=n;i++){
    		if(i==n) f[i]=10;
    		else{
    			f[i]=po[n-i-1]*10*9*2%mod;
    			if(i+1+1<=n)
    				f[i]=(f[i]+po[n-i-2]*10*9*9*(n-i-1))%mod;
    		}
    		printf("%lld ",f[i]);
    	}
    	return 0;
    }
    
  • 相关阅读:
    11.变分推断
    10.高斯混合模型GMM
    9.EM 算法
    8.指数族分布
    7.概率图模型(表示/推断/学习)
    6.核方法
    二分查找
    2.3 数据结构---数组(连续)
    C#开发Windows服务的基础代码
    C#与C++之间类型的对应{转}
  • 原文地址:https://www.cnblogs.com/BakaCirno/p/12556916.html
Copyright © 2011-2022 走看看