[CF932E]Team Work
Team Work
題解
數學題都貞德好討厭呀
開始推公式。
由於當時可以直接用暴力做了,我們下面只考慮的情況。
原式
。
現在這個樣子其實可以直接用斯特林數做了,但我們還是先考慮將斯特林數展開一下
原式
我們設,,也就是後面那一塊。
我們考慮通過線性遞推的方式處理,計算,可得,
所以,得到遞推式
我們只需要線性處理出組合數與的值即可,時間複雜度,也可以用埃篩的方式線性求出。
原始碼
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define MAXN 5005
const double eps=1e-7;
const int INF=0x7f7f7f7f;
const LL mo=1e9+7;
const int inv2=5e8+4;
typedef pair<int,int> pii;
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
_T f=1;x=0;char s=getchar();
while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
x*=f;
}
int qkpow(int a,int s){
int t=1;
while(s){
if(s&1)t=1ll*a*t%mo;
a=1ll*a*a%mo;s>>=1;
}
return t;
}
int add(int x,int y){return x+y>=mo?x+y-mo:x+y;}
int n,k,f[MAXN],c[MAXN],inv[MAXN],pw[MAXN],prime[MAXN],cntp;
void init(){
c[0]=inv[1]=pw[1]=1;c[1]=n;
for(int i=2;i<=k+1;++i){
inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
c[i]=1ll*c[i-1]*inv[i]%mo*(n-i+1)%mo;
if(!pw[i])prime[++cntp]=i,pw[i]=qkpow(i,k);
for(int j=1;j<=cntp&&i*prime[j]<=k;++j){
pw[i*prime[j]]=1ll*pw[i]*pw[prime[j]]%mo;
if(i%prime[j]==0)break;
}
}
}
int work1(){
int res=0;
for(int i=1;i<=n;++i)
res=add(res,1ll*c[i]*pw[i]%mo);
return res;
}
int work2(){
int mul,c2,res=0;mul=c2=f[k]=1;
for(int i=k-1;i>0;--i){
c2=1ll*c2*(n-i-1)%mo*inv[k-i]%mo;
mul=1ll*mul*(mo-inv2)%mo;
f[i]=add(1ll*c2*mul%mo,1ll*inv2*f[i+1]%mo);
}
mul=inv2;
for(int i=1;i<=k;++i){
res=add(res,1ll*pw[i]*c[i]%mo*mul%mo*f[i]%mo);
mul=1ll*mul*inv2%mo;
}
res=1ll*res*qkpow(2,n)%mo;
return res;
}
signed main(){
read(n);read(k);init();
if(n<=k+1)printf("%d\n",work1());
else printf("%d\n",work2());
return 0;
}
謝謝!!!
相關文章
- cf932E. Team Work(第二類斯特靈數 組合數)
- Team Queue
- Android workAndroid
- Best Team With No Conflicts
- work 10月
- golang work poolGolang
- Team Queue(佇列)佇列
- Codeforces——231A Team
- MySQL-workbench not workMySql
- queue:work 原理分析
- RabbitMQ-Work模式MQ模式
- Team - 協同工具Confluence
- 1383. Maximum Performance of a TeamORM
- Joe Harris is a real problem with this team
- CF1316E Team BuildingUI
- 滲透Hacking Team過程
- misdirection靶機work_through
- LamPiao靶機work_throughLAMP
- How Logs Work On MySQL With InnoDB TablesMySql
- Project Management - 2) Estimate Your WorkProject
- Hacking Team攻擊程式碼分析
- How does an Electric Motor work? (DC Motor)
- WPF Backgroundworker dowork work completed progress changed
- RabbitMQ(二)JavaClient SpringBoot整合 Work queuesMQJavaclientSpring Boot
- (翻譯) How i work - Taylor Otwell
- RabbitMQ學習筆記-Work QueuesMQ筆記
- 簡介我的 Git Work FlowGit
- CF1886E I Wanna be the Team Leader
- EA has continued to update Madden 21 Ultimate Team
- The Buffalo Bills may be the third most popular team in their nation
- Hacking Team系列 Flash 0Day分析
- Hacking Team 新 Flash 0day分析
- rhel7網路卡bond和team
- sx-work網路繫結IP
- PostgreSQL DBA(167) - pgAdmin(config:work_mem)SQL
- Team Queue (佇列的一種應用)佇列
- iOS - No account with iTunes Connect access have been found for the teamiOS
- Source Code Reading for Vue 3: How does `hasChanged` work?Vue