2017 ACM-ICPC Asia East Final T1

做完顿时大学不想搞ACM

好弱啊只会T1,在Chemist&&wxh两位dalao的指导下搞懂。

题解如下。【手写版本 滑稽

code

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 ll moder=1e9+7;
 5 int T;
 6 ll a[200000],c[200000];
 7 ll ksm(ll a,ll b)
 8 {
 9     ll ans=1;
10     while(b)
11     {
12         if(b&1) ans=ans*a%moder;
13         b>>=1;
14         a=a*a%moder;
15     }
16     return ans%moder;
17 }
18 int main()
19 {
20     scanf("%d",&T);
21     for(int i=1;i<=T;i++)
22     {
23         ll n=0;int k=0;
24         scanf("%lld%d",&n,&k);
25         for(int j=1;j<=k;j++) a[j]=0,c[j]=0;
26         a[1]=1;c[0]=1;
27         ll sum=1;//c[0]
28         for(int j=2;j<=k;j++)
29         {
30             a[j]=-(moder/j)*a[moder%j];
31             a[j]=(a[j]%moder+moder)%moder;
32         }
33         for(int j=1;j<=k-1;j++)
34         {
35             c[j]=(c[j-1]%moder*(n-j+1)%moder*a[j]%moder)%moder;
36             sum=(sum+c[j])%moder;
37         }
38         ll t=ksm(2,n);
39         printf("Case #%d: %lld\n",i,((t+moder)-sum)%moder);
40     }
41     
42     return 0;
43 }
View Code

猜你喜欢

转载自www.cnblogs.com/nopartyfoucaodong/p/9192494.html