Balala power!
Time limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 2668 Accepted Submission (s): 562
Problem Description
Sample Input
1a2aabb3abaabc
Sample Output
Case #1:25Case #2:1323Case #3:18221
Source multi-university Training contest-team 1 topics Link: http://acm.hdu.edu.cn/showproblem.php?pid=6034
Test instructions: give you n a string of lowercase letters, let you assign 26 letters 0-25, each string form a 26 binary number, ask how to divide
The weighted value of this n number and maximum. (cannot have a leading 0, but a single 0 can)
Solution: Each character's contribution to the answer can be viewed as a 26-digit number, and the question is equivalent to adding a 0 to 25 weight to these contributions.
Make the answer the most. The maximum number matches 25, the second largest number matches 24, and so on. After ordering this greedy in turn, the only thing to note is not to appear
Leading 0. The key is the sort, in fact the structure of the order can be sorted by the array dictionary order!
The AC code is given below:
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 Constll mod=1e9+7;5 Constll n=1e5+Ten;6ll fac[n]={1};7ll temp[ -];8ll hash[ -];9 BOOLleap[ -];Ten CharStr[n]; One structNode A { - ll Cnt[n]; - ll ID; the BOOL operator< (ConstNode &p)Const - { - for(LL i=n-1; i>=0; i--) - { + if(cnt[i]>P.cnt[i]) - return true; + Else if(cnt[i]<P.cnt[i]) A return false; at Else; - } - } -}p[ -]; - intMain () - { inll n,tcase=1; - for(LL i=1; i<n;i++) tofac[i]=fac[i-1]* -%MoD; + while(SCANF ("%lld", &n)! =EOF) - { theMemset (P,0,sizeof(P)); *memset (hash,-1,sizeof(Hash)); $memset (Leap,false,sizeof(Leap));Panax Notoginsengll r=0; - for(LL i=1; i<=n;i++) the { +scanf"%s", str); All len=strlen (str); theR=max (r,len-1); + if(len!=1) -leap[str[0]-'a']=1; $ for(LL i=0; i<len;i++) $p[str[i]-'a'].cnt[len-(i+1)]++; - } - for(LL i=0;i< -; i++) the { - for(LL j=0; j<n;j++)Wuyi { the if(p[i].cnt[j]>= -) - { Wup[i].cnt[j+1]+=p[i].cnt[j]/ -; -p[i].cnt[j]%= -; About } $ } -P[i].id=i; - } -Sort (p,p+ -); A for(LL i=0;i< -; i++) +hash[p[i].id]= --(i+1); the for(LL i=0;i< -; i++) - { $ if(leap[p[i].id]&&hash[p[i].id]==0) the { the for(LL j= -; j>=0; j--) the { the if(!Leap[p[j].id]) - { in for(LL k= -; k>=j+1; k--) the { thehash[p[k].id]=hash[p[k-1].id]; About } thehash[p[j].id]=0; the Break; the } + } - Break; the }Bayi } thell ans=0; the for(LL i=0;i< -; i++) - { - for(LL j=0; j<n;j++) the { theAns= (ans+fac[j]*p[i].cnt[j]*hash[p[i].id]%MoD); the } the } -printf"Case #%lld:%lld\n", tcase++,ans%MoD); the } the return 0; the}
Multi-university Training contest-team 1 1002&&hdu 6034 balala power! "string, greedy + sort"