CF1422C Bargain (DP+Thinking+Mathematics)

Link

Title:

Given an integer n ( 1 ≤ len ( n ) < 1 0 5 n(1 \leq len(n) < 10^5n(1l e n ( n )<105 , wherelen(n) len(n)l e n ( n ) meansnnThe number of digits of n )) , now it is stipulated that each round of Vova can take out a continuous number of digits, and the remaining digits are the score of the round. The result can have leading0 00 . In particular, if Vova takes all numbers, the round scores0 00 .

Now ask you to find the sum of the scores of all the different ways of taking the pair 1 0 9 + 7 10^9+7109+The value after modulo 7. In particular, if there are many different ways to get the same number, the score will be counted multiple times.

analyze:

First, let's analyze the number in the i-th place to see how much he can contribute:
There are two (three) ways that he can contribute:

  • delete the number in front of the i bit
  • delete the number after the i bit
  • Delete a continuous segment containing i-bits (delete does not contribute)

Then we analyze the contribution made by deleting the number in front of the i-bit: First of all, it is certain that the contribution of the i-bit is unchanged before deleting the i-bit, which is str [ i ] ∗ 1 0 len − i + 1 str[i] *10^{len-i+1}s t r [ i ]10l e n i + 1 Then we only need to calculate how many times, just look at how many kinds of intervals there are in the previous paragraph? Select 2 numbers from the previous (i-1) numbers as the left and right intervals, which is (i-1)*i/2.

Then look at the contribution made by the number after deleting the i-bit: the same as the analysis of the number before deleting the i-bit, the difference is that the contribution of the i-bit changes, we find that his contribution changes like this 1, 20, 300, 4000..., because each When there is one more behind him, there is one more choice.

/// 欲戴皇冠,必承其重。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef unsigned long long ull;

#define x first
#define y second
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define debug(x) cout << #x << ": " << x << endl;

const int MOD = 998244353;
const int mod = 1e9+7;
const int N = 5e5 + 10;
const int dx[] = {
    
    0, 1, -1, 0, 0, 0, 0};
const int dy[] = {
    
    0, 0, 0, 1, -1, 0, 0};
const int dz[] = {
    
    0, 0, 0, 0, 0, 1, -1};
int day[] = {
    
    0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll n, m,p;
string str;

void solve()
{
    
    
    cin>>str;
    ll len=str.size();
    str=" "+str;
    ll ans=0;
    ll sum=0;
    p=1;
    for(ll i=len;i>=1;i--){
    
    
        ll now = (i-1)*i/2;
        ans = (ans+p*(str[i]-'0')%mod*now%mod)%mod;///只删前面】
        ans = (ans + sum * (str[i]-'0') % mod ) % mod;///只删后面
        sum = (sum + (len-i+1) *p %mod) % mod;
        p = p * 10 % mod;
    }
    printf("%lld\n",ans);
}    
int main()
{
    
    
    ll t = 1;
    ///scanf("%lld", &t);
    while(t--)
    {
    
    
        solve();
    }
    return 0;
} 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263436&siteId=291194637