Strong Array Time limit:3000/1000ms (java/other) memory limit:65535/32768k (java/other) Total S Ubmission (s): 18 accepted submission (s): 8font:times New Roman | Verdana | Georgiafont Size:←→problem Description A,b,c is a three-element array of n, a={a1,a2,a3...an},b={b1,b2,b3...bn},c={c1,c2,c3...cn};
A, b arrays are known, and CI equals AI or bi (1<=i<=n), there is no doubt that there are many combinations of C arrays.
But ZZ does not want the C array to consist entirely of an array of a or B, each of which has a K value, K=C1*C2*C3*...*CN. The
now requires you to find out the corresponding k values for each combination and add them together. This result can be very large, please take the answer to 1e9+7.
For example a={1,2,3} b={2,2,4}. The
C array may be {a1,b2,b3} {b1,a2,b3} {b1,b2,a3} {a1,a2,b3} {a1,b2,a3} {b1,a2,a3}
K values are 8,16,12,8,6,12 respectively, so you should output 62.
A large number of inputs, it is recommended to use Scanfinput input data containing multiple test instances, the first line of each test instance has only one integer n (1<=n<=100000), the number of a,b,c array elements, the second row has n data representation A1 A2 A3 ... an, the third row has n data representing B1 B2 b3...bn, (1<=AI,BI<=1E9). Process to the end of the file.
Output for each test instance, outputting one row of data to represent the answer to the question, 1e9+7 the answer to the model. Sample Input
2 2 4134
sample Output
620
Problem Solving idea: This is a math problem, analysis can know such a formula.
k= (A[1]+b[1]) * (a[2]+b[2]) *...* (A[n]+b[n])-a[1]*a[2]*...*a[n]-b[1]*b[2]*...*b[n];
Because the data will be very large, so 1e9+7 to the surplus.
PS: This question I guess is mathematics, but helpless cannot push out the formula ...
Code:
1#include <iostream>2#include <stdio.h>3 using namespacestd;4 inta[100005],b[100005];5 Long Longinf=1e9+7;6 intMain ()7 {8 intN;9 while(~SCANF ("%d",&N)) {Ten for(intI=1; i<=n;i++) Onescanf"%d",&a[i]); A for(intI=1; i<=n;i++) -scanf"%d",&b[i]); - Long Longans=1, cnt=1, sum=1; the for(intI=1; i<=n;i++){ -ans*=A[i]; -ans%=INF; - } + for(intI=1; i<=n;i++){ -cnt*=B[i]; +cnt%=INF; A } at for(intI=1; i<=n;i++){ -Sum*= (a[i]+b[i]); -sum%=INF; - } -sum= (sum+inf-ans+inf-cnt)%INF; -cout<<sum<<Endl; in } - return 0; to}
JXNU ACM Tryouts An array of strong