Sum

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

Problem 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 1,2,3,12,23,123.

In first column, you can get 6 digit strings totally, which are 1,4,7,14,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

3
123
456
789

Sample Output

2784

题目主要是导出公式:

如n行n列的每一行的和sum=1111.....111(n个1)*A1+111...111(n-1个1)*2*A2+.........+11*(n-1)*An-1+1*n*An;

好吧。。这么写果然还是不怎么完整。。如今补充一下。。

拿第一行 1 2 3来说。。

1 仅仅能由他本身, 即 sum+=A1。  2 能有2, 12。则 sum+=A2+10*A1+A2;   3 能有3, 23 ,123,则:

sum+=A3+10*A2+A3+100*A1+10*A2+A3......合算的sum=111*A1+11*2*A2+1*3*A3;也就是上面说的那个公式。

别忘了计算列的sum.



#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;
}

ACdream: Sum的更多相关文章

  1. 聚合函数:sum,count,max,avg

    聚合函数:sum,count,max,avg等,一般作用于多条记录上.通过group by可以将数据对属于一组的数据起作用. SELECT region, SUM(population), SUM(a ...

  2. LeetCode129:Sum Root to Leaf Numbers

    题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a nu ...

  3. 每日一九度之 题目1038:Sum of Factorials

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2109 解决:901 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, ...

  4. acdream Divide Sum

    Divide Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitSta ...

  5. acdream 1431 Sum vs Product

    Sum vs Product Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  6. Hive函数:SUM,AVG,MIN,MAX

    转自:http://lxw1234.com/archives/2015/04/176.htm,Hive分析窗口函数(一) SUM,AVG,MIN,MAX 之前看到大数据田地有关于max()over(p ...

  7. LeetCode之“树”:Sum Root to Leaf Numbers

    题目链接 题目要求: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represe ...

  8. ACM1001:Sum Problem

    Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.   Input ...

  9. HDU - 4676 :Sum Of Gcd (莫队&区间gcd公式)

    Given you a sequence of number a 1, a 2, ..., a n, which is a permutation of 1...n. You need to answ ...

随机推荐

  1. 数据和C

    整数就是没有小数部分的数,在C中小数点永远不会出现在整数中.例如2,-24,2456都是整数,整数以二进制存储,例如7的二进制表示为111,在8位的字节中存储它的前5位为0,将后3位置1. 浮点数即加 ...

  2. PySide——Python图形化界面

    PySide——Python图形化界面 PySide——Python图形化界面入门教程(四) PySide——Python图形化界面入门教程(四) ——创建自己的信号槽 ——Creating Your ...

  3. 运行yum报错Error: Cannot retrieve metalink for reposit

    http://www.netpc.com.cn/593.html 运行yum报错Error: Cannot retrieve metalink for reposit 今天给Centos通过rpm - ...

  4. hdu 4277

    题目链接 #include <cstdio> //by-ACMer_xiaohao #include <cstring> #include <map> using ...

  5. 构建基于Javascript的移动web CMS——模板

    在上一篇<构建基于Javascript的移动CMS--Hello,World>讲述了墨颀 CMS的大概组成,并进行了一个简单的演示样例,即Hello,World.这一次,我们将把CMS简单 ...

  6. Java Web Services (0) - Overview

    前言第1章 Web服务快速入门 1.1 Web服务杂项 1.2 Web服务有什么好处 1.3 Web服务和面向服务的架构 1.4 Web服务简史 1.4.1 从DCE/RPC到XML-RPC 1.4. ...

  7. shell 调试

    感觉编写shell在查找错误的过程中,很让你崩溃,还好shell也提供了一些调试的方式: 语法检查      -n选项做语法检查,而不执行脚本      sh -n script_name.sh 启动 ...

  8. CentOS 6.4下编译安装MySQL 5.6.16

    一.卸载旧版本号MySql 1.rpm卸载: 1> 检查安装包: rpm -qa | grep mysql 2> 普通删除: rpm -e mysql-5.6.16.rpm 3> 强 ...

  9. 纠正一个概念:类就有VMT,各实例不过是共享这个VMT而已

    不是只有实例才有VMT,举个例子,各实例的VMT地址是相同的: Use System.Contnrs; procedure TForm1.BitBtn2Click(Sender: TObject); ...

  10. [Windows Phone]修改应用程序主题

    问题: Windows Phone模拟器默认情况下是黑色(Dark)主题,开发者往往都是在黑色主题下进行应用开发,加入自定义的颜色,样式等等,而当把手机操作系统主题设为白色(Light)主题之后会发现 ...