[CC-CMPVIRS] Computer Virus

Source: Internet
Author: User
[CC-CMPVIRS] computer virus questions:

There is a tape, which is divided from left to right into \ (n \ le10 ^ 7) \) grids. At the beginning, the # \ (I \) number \ (I \) on the grid \). This tape is divided into consecutive \ (M \ le10 ^ 3) \) segments from left to right. The smaller segment is on the left of the larger segment, and each grid is allocated to a segment. The \ (I \) segment has \ (d_ I \) grids.
In addition, the number of cells with a large number cannot be smaller than the number of smaller segments, that is, \ (d_ I \ le D _ {I + 1 }\).
At the beginning, all the grids were white. Now, repeat the following operations until all the grids are dyed black:

  1. Dye the last lattice of each segment into black.
  2. Change the number written on each white lattice to the sum of the number written on it and the white lattice on its left. In this process, all the white grids are completed at the same time.

Calculate the number and, modulo \ (10 ^ 9 + 7 \) on the grid after all the grids are dyed black \).

Ideas:

Make some reasonable guesses to draw a conclusion (see the code ).

For proof, see the official question.

Source code:
#include<cstdio>#include<cctype>inline int getint() {    register char ch;    while(!isdigit(ch=getchar()));    register int x=ch^'0';    while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');    return x;}typedef long long int64;const int M=1001,mod=1e9+7;inline int power(int a,int k) {    int ret=1;    for(;k;k>>=1) {        if(k&1) ret=(int64)ret*a%mod;        a=(int64)a*a%mod;    }    return ret;}int d[M];int main() {    const int n=getint(),m=getint();    int ans=mod-m;    for(register int i=1;i<=m;i++) {        int tmp=1;        d[i]=getint();        for(register int j=0;j<i;j++) {            tmp=(int64)tmp*power(i-j+1,d[j+1]-d[j])%mod;        }        (ans+=tmp)%=mod;    }    printf("%d\n",ans);    return 0;}

[CC-CMPVIRS] Computer Virus

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.