比赛过程
签到题写的时间有点长了,半天才找到规律,签完到一直在写斐波那契,没想到是个卡常数的题,需要各种打表,T到飞起。
题解
1004
题意
问你长度为n的26个字母随机组成的字符串中据有最少回文子串的种类有多少。
解法
发现其实三各不同字母拼在一起循环组成的字符串的回文子串最少,所以答案就是262524,注意特判 n = 1 , 2 , 3 n=1,2,3 n=1,2,3。
代码
#include<bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define RFOR(a,b,c) for(int a=b;a>=c;a--)
using namespace std;
int main() {
IO;
int t;
cin >> t;
while(t--){
int n;
cin >> n;
if(n==1)
cout << 26 << endl;
else if(n==2)
cout << 676 << endl;
else if(n==3){
cout << 17576 << endl;
}
else {
ll ans = 26 * 25 * 24;
cout <<ans<< endl;
}
}
return 0;
}
1005
题意
F F F 是斐波那契数列,求 ( F 0 ) k + ( F c ) k + ( F 2 c ) k + … + ( F n c ) k (F_0)^k+(F_c)^k+(F_{2c})^k+…+(F_{nc})^k (F0)k+(Fc)k+(F2c)k+…+(Fnc)k,其中 1 ≤ n , c ≤ 1 e 18 , 1 ≤ k ≤ 1 e 5 。 结 果 对 1 e 9 + 9 取 模 。 1\leq n,c\leq 1e18,1\leq k\leq 1e5。结果对1e9+9取模。 1≤n,c≤1e18,1≤k≤1e5。结果对1e9+9取模。
解法
看了人家的题解才知道什么是把预处理做到极致,开头是组合数预处理阶乘和阶乘的逆元,1e5复杂度,这道题T有200左右,这样是合算的,然后手动预处理出
1
+
5
2
\frac{1+\sqrt 5}{2}
21+5和
1
−
5
2
\frac{1-\sqrt 5}{2}
21−5在模1e9+9的情况(之前没仔细看题,拿1e9+7算了好多次)然后求出ac和bc,根据递推求出ti,复杂度为O(K),最后一个优化是欧拉降幂(真是简单又实用的东西,学到了学到了)。
代码
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
#include<unordered_map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (ll ll i = a; i < n; i++)
#define ford(i, a, n) for (ll ll i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define ss(a) scanf("%s", a);
#define debug(a) cout << a << endl
#define pr(a) printf("%d ", a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
#define py puts("Yes")
#define pn puts("No")
#define pY puts("YES")
#define pN puts("NO")
#define re(i, a, b) for (int i = a; i <= b; ++i)
#define de(i, a, b) for (int i = a; i >= b; --i)
#define all(x) (x).begin(), (x).end()
const double eps = 1e-3;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const ll inf = 0x3f3f3f3f;
template <class T>
inline void cmin(T &a, T b) { ((a > b) && (a = b)); }
template <class T>
inline void cmax(T &a, T b) { ((a < b) && (a = b)); }
const int MAXN = 1e5 + 10;
const ll mode = 1e9 + 9;
//快读-----------------------------------------------------------------------------------------
namespace fastIO
{
#define BUF_SIZE 100000
#define OUT_SIZE 100000
//fread->read
bool IOerror = 0;
//inline char nc(){char ch=getchar();if(ch==-1)IOerror=1;return ch;}
inline char nc()
{
static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
if (p1 == pend)
{
p1 = buf;
pend = buf + fread(buf, 1, BUF_SIZE, stdin);
if (pend == p1)
{
IOerror = 1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; }
template <class T>
inline bool read(T &x)
{
bool sign = 0;
char ch = nc();
x = 0;
for (; blank(ch); ch = nc())
;
if (IOerror)
return false;
if (ch == '-')
sign = 1, ch = nc();
for (; ch >= '0' && ch <= '9'; ch = nc())
x = x * 10 + ch - '0';
if (sign)
x = -x;
return true;
}
inline bool read(double &x)
{
bool sign = 0;
char ch = nc();
x = 0;
for (; blank(ch); ch = nc())
;
if (IOerror)
return false;
if (ch == '-')
sign = 1, ch = nc();
for (; ch >= '0' && ch <= '9'; ch = nc())
x = x * 10 + ch - '0';
if (ch == '.')
{
double tmp = 1;
ch = nc();
for (; ch >= '0' && ch <= '9'; ch = nc())
tmp /= 10.0, x += tmp * (ch - '0');
}
if (sign)
x = -x;
return true;
}
inline bool read(char *s)
{
char ch = nc();
for (; blank(ch); ch = nc())
;
if (IOerror)
return false;
for (; !blank(ch) && !IOerror; ch = nc())
*s++ = ch;
*s = 0;
return true;
}
inline bool read(char &c)
{
c = nc();
if (IOerror)
{
c = -1;
return false;
}
return true;
}
template <class T, class... U>
bool read(T &h, U &... t) { return read(h) && read(t...); }
#undef OUT_SIZE
#undef BUF_SIZE
}; // namespace fastIO
using namespace fastIO;
//-----------------------------------------------------------------------------------------
ll Pow(ll a, ll b)
{
ll sum = 1;
a = a % mode;
while (b > 0)
{
if (b % 2 == 1) //判断是否是奇数,是奇数的话将多出来的数事先乘如sum
sum = (sum * a) % mode;
b >>= 1;
a = (a * a) % mode; // 不断的两两合并再取模,减小a和b的规模
}
return sum;
}
//----------------------------------------------------------------
ll a[MAXN],b[MAXN];
ll GC(ll x,ll y)
{
ll tem=a[x]*b[y]%mode*b[x-y]%mode;
return tem;
}
int main()
{
ll t,N,C,K;
read(t);
a[0]=1;
const int M=1e5;
re(i,1,1e5)a[i]=a[i-1]*(ll)i%mode;
b[M]=Pow(a[M],mode-2);
de(i,M-1,0)b[i]=b[i+1]*(ll)(i+1)%mode;
while (t--)
{
read(N);read(C);read(K);
ll A=691504013,B=308495997;
A=Pow(A,C%(mode-1));
B=Pow(B,C%(mode-1));
ll a=1;
ll b=Pow(B,K);
ll ib=Pow(B,mode-2);
ll ans=0;
re(i,0,K)
{
ll x=a*b%mode;
if(x==1)
x=(N+1)%mode;
else
x=(Pow(x,(N+1)%(mode-1))-1+mode)%mode*Pow((x-1+mode)%mode,mode-2)%mode;
if((K-i)&1)
x=(x==0?x:mode-x);
ans=(ans+GC(K,i)*x%mode)%mode;
a=a*A%mode;
b=b*ib%mode;
}
ll mul=276601605;
mul=Pow(mul,K);
ans=ans*mul%mode;
printf("%lld\n",ans);
}
}