ACdream: Sum, acdreamsum

Source: Internet
Author: User

ACdream: Sum, acdreamsum

SumTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStatisticNext ProblemProblem Description

You are given an N * N digit matrix and you can get several horizontal or vertical digit strings from any position.

For example:

123

456

789

In first row, you can get 6 digit strings totally, which are 23,123.

In first column, you can get 6 digit strings totally, which are 47,147.

We want to get all digit strings from each row and column, and write them on a paper. now I wonder the sum of all number on the paper if we consider a digit string as a complete decimal number.

Input

The first line contains an integer N. (1 <=n <= 1000)

In the next N lines each line contains a string with N digit.

Output

Output the answer after module 1,000,000,007 (1e9 + 7 ).

Sample Input
3123456789
Sample Output
2784

The main question is to export the formula:

For example, sum = 1111 for each row of n rows and n columns ..... 111 (n 1) * A1 + 111... 111 (N-1 1) * 2 * A2 + ......... + 11 * (n-1) * An-1 + 1 * n *;

Okay .. This writing is still incomplete .. Now, I want to add more information ..

Take the first line 1 2 3 for example ..

1 can only be set by itself, that is, sum + = A1. 2 can have 2, 12. Then sum + = A2 + 10 * A1 + A2; 3 can have 3, 23,123, then:

Sum + = A3 + 10 * A2 + A3 + 100 * A1 + 10 * A2 + a3 ...... sum = 111 * A1 + 11*2 * A2 + 1*3 * A3; that is, the formula mentioned above.

Do not forget to calculate the sum of columns.



#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<queue>#include<vector>#define M 1000000007#define f1(i, n)  for(int i=1; i<=n; i++)#define f2(i, n)  for(int i=0; i<n; i++)#define f3(j, n)  for(int j=0; j<n; j++) using namespace std;char a[1050][1050];long long int b[1050];int main(){    int n;    int k=1050;    f1(i, k)       b[i]=0;    f1(i, k)       for(int j=1; j<=i; j++)        b[i]=(b[i]*10+1)%M;    while(~scanf("%d",&n))    {        k=n;        long long int sum=0;        f2(i, k)        {            scanf("%s",&a[i]);           // f3(j, k)           for(int j=0; j<n; j++)                sum=(sum+((((j+1)*((long long)a[i][j]-'0'))*b[n-j])%M))%M;        }        //f3(j, k)        for(int j=0; j<n; j++)        {            f2(i, k)                sum=(sum+((((i+1)*((long long)a[i][j]-'0'))*b[n-i])%M))%M;        }        cout<<sum<<endl;    }    return 0;}





What is SUM (A2: B34) in Excel?

"-" In sum (G16-I16) is a minus sign... Actually, sum is the same here.
SUM (A2: B34) "A2: B34" refers to all cells in the range of a rectangle from A2 to B34.
= SUM (B22, B23, B34, B35) comma is the symbol used in the function to divide the parameters. Here, we SUM the cells B22, B23, B34, and B35.
* Title
/Division number
$ Absolute reference means that the row number or column number behind $ will not change when dragging and filling

What is SUM (B: B) in Excel?

SUM (B: B) sums the values of Column B.
If SUM (A: B) is used, the AB column is summed.
If SUM (A1: B10) is used, it is used to SUM the rectangular area of the 10 rows in the two columns of A1: B10.

However, if the SUM is only for Column B, it cannot be written as SUM (B) or SUM (B: B), which references the entire column; or SUM (B1: B100, reference area.

Ask.

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.