Educational Codeforces Round 84 (Rated for Div. 2)E:Count The Blocks 组合计数/线性递推

解法一:

由于是0-10^n-1  ,每个位置的长度为i的贡献互相独立。

我们可以把长度为i当成一个数,插入到n-i个数的n-i+1个空位中

插在两侧:与其相邻的数9种取法,其余是10种,

插在中间:与其相邻的2个数各9种,其余10种

我们每次插好位置后,求的是长度为i在从前往后数第j个位置上的贡献,不会重复,  比如n=2,长度为1,12  1和2都要在位置1,位置2上加一次,12这个数对长度为1 的贡献是2.

所以直接for一遍即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
const  int mod =998244353 ;
ll qpow(ll a,ll b)
{
//	if(b<=0)return a;
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n;
  	cin>>n;
  	ll sm=10,ans=10;
  	for(int i=1;i<=n;i++)
  	{
  		ll ans=0;
  		if(i==n)ans=10; 
		if(n-i-1>=0)ans=qpow(10,n-i-1)*9*10*2%mod;//长度为i的块插到两头 
  		if(n-i-2>=0)ans=(ans+qpow(10,n-i-2)*81*10*(n-i-1)%mod)%mod;
  		cout<<ans<<" ";
	}
	return 0;
}
//2610 180 10

解法二:

dp[i]表示n等于i时,长度为1的个数

由于n等于i时,长度 为j的个数等于    n取i-1,长度为j-1的个数

我们只需要求出dp[i]即可

由于每个数字的贡献是一定的,我们又知道了所有除了长度为1的所有情况。

只需要让数字总数减去前面的数字贡献即可。。用sum加速下就行

dp[i] = i * pow(10, i) - i * dp[1] - (i - 1) *dp[2] …… - 2 * dp[i - 1]

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
const  int mod =998244353 ;
ll qpow(ll a,ll b)
{
//	if(b<=0)return a;
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ans;
}
ll dp[M];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n;
  	cin>>n;
  	dp[1]=10;
  	ll sm=10,ans=10;
  	for(int i=2;i<=2e5;i++)
  	{
  		ll tp=qpow(10,i)*i%mod;
  		ans=(ans+sm)%mod;
  		dp[i]=(tp-ans+mod)%mod;
  		ans=(ans+dp[i])%mod;
  		sm=(sm+dp[i])%mod;
	}
	for(int i=1;i<=n;i++)
	cout<<dp[n-i+1]<<" ";
	return 0;
}
//2610 180 10

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值