标签:des style java color strong os
题目主要是导出公式:
如n行n列的每一行的和sum=1111.....111(n个1)*A1+111...111(n-1个1)*2*A2+.........+11*(n-1)*An-1+1*n*An;
求1111111...111我用到打表减少时间复杂。
AC代码如下:
#include<iostream> #include<cstdio> #include<cstring> #include<queue> #define M 1000000007 #define min(a,b) (a<b?a:b) using namespace std; char a[1005][1005]; long long b[1005]; int main() { int n; long long i,j; for(i=1;i<=1005;i++) b[i]=0; for(i=1;i<=1005;i++) for(j=1;j<=i;j++) { b[i]=(b[i]*10+1)%M; } while(~scanf("%d",&n)) { long long sum=0; for(i=0;i<n;i++) { scanf("%s",&a[i]); for(j=0;j<n;j++) sum=(sum+((((j+1)*((long long)a[i][j]-'0'))*b[n-j])%M))%M; } for(j=0;j<n;j++) { for(i=0;i<n;i++) sum=(sum+((((i+1)*((long long)a[i][j]-'0'))*b[n-i])%M))%M; } cout<<sum<<endl; } return 0; }
ACdream原创群赛(16) J,布布扣,bubuko.com
标签:des style java color strong os
原文地址:http://blog.csdn.net/hanhai768/article/details/37720591