标签:数学
1.题目描述:点击打开链接
2.解题思路:比赛时没有想到好的思路,后来才发现,只需要t串中的字符是s串中出现次数最多的字符即可,根据乘法原理可知:最终结果是pow(num,n),其中num是s串中次数最多的字符的个数。
3.代码:
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #include<vector> #include<stack> #include<map> #include<queue> #include<deque> #include<cstdlib> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<functional> using namespace std; int n; const int MOD = 1000000000 + 7; string s; int vis[4]; char*cg = "ACGT"; int id(char c){ return strchr(cg, c) - cg; } int P(int e, int n) { if (n == 0)return 1; int x = P(e, n / 2); long long ans = (long long)x*x%MOD; if (n & 1)ans = ans*e%MOD; return (int)ans; } int main() { //freopen("test.txt", "r", stdin); while (cin >> n) { cin >> s; int cnt = 0; int num = 0; int len = s.length(); memset(vis, 0, sizeof(vis)); for (int i = 0; i < len; i++) { vis[id(s[i])]++; cnt = max(cnt, vis[id(s[i])]); } for (int i = 0; i < 4;i++) if (vis[i] == cnt) num++; cout << P(num, n) << endl; } return 0; }
标签:数学
原文地址:http://blog.csdn.net/u014800748/article/details/44022795