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;
    }
    
  • 相关阅读:

    python内存管理
    python-继承类执行的流程
    Redis-key的设计技巧
    Redis-误操作尝试恢复
    Python3之hashlib
    面相对象
    设计模式
    RESTful API规范
    Django中间件执行流程
  • 原文地址:https://www.cnblogs.com/BakaCirno/p/12556916.html
Copyright © 2011-2022 走看看