很慢得速度做完了A;
B一直WA,考完才发现读错题了;
考完发现C也很简单。。
先说A题:
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.
Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s, t) can be used to define the function of Vasya distance ρ(s, t):
where
is obtained from string
s, by applying left circular shift
i times. For example,
ρ("AGC", "CGT") =
h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") +
h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") +
h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") =
1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6
Vasya found a string s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: .
Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109 + 7.
Output
Print a single number — the answer modulo 109 + 7.
Note
Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.
In the first sample, there is ρ("C", "C") = 1, for the remaining strings t of length 1 the value of ρ(s, t) is 0.
In the second sample, ρ("AG", "AG") = ρ("AG", "GA") = ρ("AG", "AA") = ρ("AG", "GG") = 4.
In the third sample, ρ("TTT", "TTT") = 27
贪心~
去掉前一个sigma,发现第二个sigma相当于让每个数字经过一次每个位置,如果新串的这个位置和当前数字相同,那么对答案贡献1。那么如果一个字母出现k次,在每一个位置对答案的贡献都是k。
而第一个sigma相当于对答案*n。
要让答案最大,就让每一位对答案的贡献都最大即可,也就是让每一位都是出现次数最多的那个字母。
那么答案就是出现次数最多的字母的种类数的n次方。
#include
#include
#include
#include
#include
#define LL long long
using namespace std;
int n,a[10];
char c[100005];
void Pow(int k,int n)
{
LL mod=(LL)1000000007;
long long ans=1LL;
for (int i=1;i<=n;i++)
ans=(ans*(LL)k)%(LL)mod;
cout<
B:
只要STL用的熟练,这题就非常简单了。
我们把当前可以拆卸的加入到set中。
什么是可以拆卸的?
1.没有被他支撑的 2.被他支撑的块的支撑物>1
然后从set中取最大/小的出来,更新set:可能是某些块能加入了,可能是某些块不能拆卸了。
注意被更新的块一定位于当前块(x,y)的x+1/x-1层,y+-1,y+-2处。
(为什么会影响y+-2处呢?因为如果(x+1,y+1)处只有(x,y)和(x,y+2)支撑,那么此时(x,y+2)就得从set中取出了)
#include
#include
#include
#include
#include
#include
#define mod 1000000009
#define LL long long
#define M 100010
#include
#include
C:
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no two pluses in such a partition can stand together (between any two adjacent pluses there must be at least one digit), and no plus can stand at the beginning or the end of a line. For example, in the string100500, ways 100500 (add no pluses), 1+00+500 or 10050+0 are correct, and ways 100++500, +1+0+0+5+0+0 or100500+ are incorrect.
The lesson was long, and Vasya has written all the correct ways to place exactly k pluses in a string of digits. At this point, he got caught having fun by a teacher and he was given the task to calculate the sum of all the resulting arithmetic expressions by the end of the lesson (when calculating the value of an expression the leading zeros should be ignored). As the answer can be large, Vasya is allowed to get only its remainder modulo 109 + 7. Help him!
Output
Print the answer to the problem modulo 109 + 7.
Note
In the first sample the result equals (1 + 08) + (10 + 8) = 27.
In the second sample the result equals 1 + 0 + 8 = 9.
一个数字x对答案的贡献可能为x*10^l(l=0,1,2...),那么我们分别计算x对答案贡献为x,10x,100x...时加号的方案数。
1.对答案贡献为x*10^l的加号方案数为C(n-2-l,k-1),也就是说在x的l位之后必定有一个加号,剩余的k-1个加号填在别的地方;这样一个一个直接算会超时,我们发现每一个数对答案的贡献都是数本身*10^l是,无论x是几,方案数都一样,因此可以枚举l,维护前缀和,直接计算所有数。
2.还要注意,如果x是出现在最后一个数字中,那么他的l位之后是没有加号的,此时x对答案的贡献是固定的,方案数为(x是第i个数)C(i-1,k),把这种情况单独加上即可。
#include
#include
#include
#include
#include
#define mod 1000000007
#define LL long long
#define M 100000+5
using namespace std;
char s[M];
LL a[M],sum[M],inv[M],fac[M],ten[M];
int n,k;
LL Getinv(LL x)
{
int n=mod-2;
LL ans=1LL,base=x;
while (n)
{
if (n&1) ans=ans*base%mod;
base=base*base%mod;
n>>=1;
}
return ans;
}
void Prepare()
{
fac[0]=inv[0]=1LL;
for (int i=1;i<=n;i++)
fac[i]=fac[i-1]*(LL)i%mod;
for (int i=1;i<=n;i++)
inv[i]=Getinv(fac[i]);
ten[0]=1LL;
for (int i=1;i<=n;i++)
ten[i]=ten[i-1]*10LL%mod;
}
LL Getc(int n,int m)
{
if (n
感悟:
1.CF对STL的考察很多,一定要好好掌握。
2.思考速度要加快!!