1327E - Count The Blocks

题意: 所有长度为n的数(不足n位用前导0补足)中,长度为i的连续的块的个数 (i=1到n)

思路:

法1: 考虑长度为i的连续区间在头尾或者在中间(在头尾需要一个数将它与其他的数隔开,在中间需要两个数将它与其他隔开,其他所有数字随意)于是每个长度都可以线性算出来

法2: 发现n= 1时1位数是10个,n=2时,2位数是10个,1位数是剩下的所有数,n=3时,3位为10,2位为之前2位数的时候的数字,延长一个,延长在哪里是等价的,所以等于n=2时1位的数字,n=3时1位为剩下的所有,就可以发现这个数列前面永远是一样的,递推就可以了

具体看代码吧讲的不是太清楚qaq

code:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
const ll mod = 998244353;

ll dp[N];

ll qpow(ll a, ll b) {
    
    
    ll ans = 1;
    while (b) {
    
    
        if (b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

int main() {
    
    
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n;
	cin >> n;
	ll sum = 10, tot = 10;
	dp[1] = 10;
	for(ll i = 2; i <= n; ++ i) {
    
    
		dp[i] = ((i * qpow(10ll, i) % mod - (sum + tot)) % mod + mod ) % mod;
		sum = (sum + dp[i] + tot) % mod;
		tot = (tot + dp[i]) % mod;
	}
	for(int i = n; i > 0; -- i) {
    
    
		cout << dp[i] << " ";
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/qq_39602052/article/details/114375059