又是神题,,,我太弱。。。
%%%(说这是大水题的神犇。。)
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define inf 0x3f3f3f3f 4 using namespace std; 5 inline int ra() 6 { 7 int x=0,f=1; char ch=getchar(); 8 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 9 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 10 return x*f; 11 } 12 const LL mod=30031; 13 int bin[20]; 14 int n,K,P,cnt; 15 int v[205]; 16 struct Maxtri 17 { 18 LL v[205][205]; 19 Maxtri(){memset(v,0,sizeof(v));} 20 friend Maxtri operator * (Maxtri a, Maxtri b) 21 { 22 Maxtri c; 23 for (int i=1; i<=cnt; i++) 24 for (int j=1; j<=cnt; j++) 25 { 26 for (int k=1; k<=cnt; k++) 27 c.v[i][j]+=a.v[i][k]*b.v[k][j]; 28 c.v[i][j]%=mod; 29 } 30 return c; 31 } 32 friend Maxtri operator ^ (Maxtri a, int b) 33 { 34 Maxtri ans; 35 for (int i=1; i<=cnt; i++) ans.v[i][i]=1; 36 for (int i=b; i; i>>=1,a=a*a) 37 if (i&1) ans=ans*a; 38 return ans; 39 } 40 }a,b,ans; 41 void dfs(int now, int num, int sta) 42 { 43 if (num==K) 44 { 45 v[++cnt]=sta; 46 return; 47 } 48 for (int i=now-1; i; i--) 49 dfs(i,num+1,sta+bin[i-1]); 50 } 51 int lowbit(int x){return x&(-x);} //lowbit有毒????!!!(是不是define的lowbit在处理==和&就sb了,,woc。。。) 52 void pre() 53 { 54 for (int i=1; i<=cnt; i++) 55 for (int j=1; j<=cnt; j++) 56 { 57 int x=(v[i]<<1)^bin[P]^v[j]; 58 if (x==lowbit(x)) b.v[i][j]=1; 59 } 60 } 61 int main(int argc, char const *argv[]) 62 { 63 bin[0]=1; for (int i=1; i<20; i++) bin[i]=bin[i-1]<<1; 64 n=ra(); K=ra(); P=ra(); 65 dfs(P,1,bin[P-1]); 66 pre(); 67 ans.v[1][1]=1; 68 Maxtri t=b^(n-K); 69 ans=ans*t; 70 printf("%d ",ans.v[1][1]); 71 return 0; 72 }