17 C Operands (Combinations and Inverses)

Given an array a of length n, define an operation as:

1. Calculate the array s of length n, such that s i = (a[1] + a[2] + ... + a[i]) mod 1,000,000,007;
2. Execute a = s;
now ask after k operations What does a look like.
Enter description:
The first line contains two integers n, k(1 <= n <= 2000, 0 <= k <= 1,000,000,000);
The second row of n integers represents the a array (0 <= a i <= 1,000,000,000).
Output description: A line of n integers representing the answer.
Example 1
enter
3 1
1 2 3
output
1 3 6
Example 2
enter
5 0
3 14 15 92 6
output
3 14 15 92 6
meaning of the title
as above
answer
Consider that the number after each operation can be deduced from the n numbers given to you
a[k][i]=k1*a[1][1]+k2*a[1][2]+k3*a[1][3]+.....+ki*a[1][i]
By playing the table to find the rules, it can be found that when k=5
a[5][1]=1*a[1][1]
a[5][2]=5*a[1][1]+1*a[1][2]
a[5][3]=15*a[1][1]+5*a[1][2]+1*a[1][3]
a[5][4]=35*a[1][1]+15*a[1][2]+5*a[1][3]+1*a[1][4]
think of combinations
35=C(3,7),15=C(2,6),5=C(1,5),1=C(0,4)
35=C(3,k+2),15=C(2,k+1),5=C(1,k),1=C(0,k-1)
The rule is found
It should be noted that the number of combinations here needs to take the remainder, and mod is a prime number, directly on the inverse element
code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll Pow(ll x,ll n)//逆元
{
    ll res=1;
    while(n)
    {
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
ll n,k,a[2005],c[2005];
void solve()
{
    ll shang=k;
    ll xia=1;
    c[ 1 ]= 1 ;
     for ( int i= 2 ;i<=n;i++) // Preprocess n number of combinations 
    {
        c [i] = (shang * Pow (xia, mod- 2 ))% mod;
        shang =shang*(k+i- 1 )% mod;
        xia =xia*i% mod;
    }
    printf("%lld",a[1]%mod);
    for(int i=2;i<=n;i++)
    {
        ll sum=0;
        for(int j=i,l=1;j>=1;j--,l++)
            sum+=a[l]*c[j]%mod;
        printf(" %lld",sum%mod);
    }
}
intmain ()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    solve();
    return 0;
}

 

Guess you like

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