Beauty of Sequence
Time limit:6000/3000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 384 Accepted Submission (s): 168
Problem descriptionsequence is beautiful and the beauty of an integer sequence are defined as follows:removes all but the First element from every consecutive group of equivalent elements of the sequence (i.e. unique function in C + + STL) and th e summation of rest integers is the beauty of the sequence.
Now is given a sequenceAOfNIntegers{A1,a2,.. . ,an} . You need find the summation of the beauty of the sub-sequence ofA. As the answer may very large, print it modulo9+7 .
Note:in Mathematics, a sub-sequence is a sequence so can be derived from another sequence by deleting some elements wit Hout changing the order of the remaining elements. For example{1,3,2} is a sub-sequence of {1,4,3,5,2,1} .
Inputthere is multiple test cases. The first line of input contains an integerT, indicating the number of test cases. For each test case:
The first line contains an integerN (1≤n≤5) , indicating the size of the sequence. The following line containsNIntegersa1,a2,.. . ,an , denoting the sequence(1≤ai≤9) .
The sum of values n for all the test cases does not exceed 2000000.
Outputfor each test case, print the answer modulo9+7 in a.
Sample Input351 2 3 4 541 2 1 353 3 2 1 2
Sample Output24054144
Sourcebestcoder Round #58 (Div.2) The main idea: Define the beauty, give an integer sequence, remove successive adjacent repeating elements in the sequence (only one), The remainder of the number and called sequence of beauty. Give you a sequence that asks you the beauty of all the subsequence sequences and the results of the 1e9+7. Thinking: We enumerate 1---n each number a[i], for A[i], how many contributions can be produced? All combinations behind I and the product of all combinations not ending with a[i] at the front of I. Now the question goes to how to maintain the number of all combinations not ending with a[i]. We define the number of combinations with event A: ending with a[i], and event B: the number of combinations not ending with a[i]. So b=2^ (i-1)-A. We can now maintain a, and indirectly maintain the B. The author is to use map maintenance, in fact, it doesn't matter.
#include <bits/stdc++.h>using namespace Std;typedef long long int;const int mod=1e9+7;const int Maxn=1e5+200;int a[ Maxn];int Pow2[maxn];map<int,int>coun;int Main () { INT t,n; scanf ("%d", &t); Pow2[0]=1; for (int i=1;i<=maxn-100;i++) { pow2[i]=pow2[i-1]*2%mod; } while (t--) { scanf ("%d", &n); for (int i=1;i<=n;i++) { scanf ("%i64d", &a[i]); } Coun.clear (); Coun[0]=1; INT ans=0; for (int i=1;i<=n;i++) { int pre=coun[a[i]]; INT Tpre=pow2[i-1]-pre; I-1 tpre= (tpre%mod+mod)%mod; INT Tmp=a[i]*tpre%mod*pow2[n-i]%mod; Ans= (ans+tmp)%mod; Pre=pow2[i-1]+pre; Coun[a[i]]=pre; } printf ("%i64d\n", ans); } return 0;}
HDU 5496--beauty of Sequence —————— "consider local"