Wannafly挑战赛5 D.子序列 组合数学

来源:互联网 发布:关联数组和索引数组 编辑:程序博客网 时间:2024/05/16 06:03

https://www.nowcoder.com/acm/contest/36/D


因为无论T串为何样,长串一定能构造出以T串为模板的串,也就是T串无论为何样,其实只是看T串的长度的影响,具体影响什么呢,

也就是m里面要选T个位置,C(m,T)这些位置固定是T的模样,其他位置可以随意构造,那么考虑容斥。对于这些选T个位置的来说,

比如3个位置里选2个位置,有a x b ,x a b,a b x。如果a x b,x a b合并,a a b会重新算一次,所以我们任意构造的时候只取25,

最后的答案是




import java.io.BufferedInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Scanner;//Array.fill(dp[i],inf)class MyInputStream extends InputStream{public BufferedInputStream bis=new BufferedInputStream(System.in);public int read() throws IOException{int i;while((i = bis.read())<48) {if(i==-1)return -1;}int temp=0;while(i>47) {temp=temp*10+i-48;i=bis.read();}return temp;}}public class Main {static int INF=(int)1e9;static final int maxn=(int)1e6+5;static int mod=(int)1e9+7;static long []fac=new long[maxn];public static long _pow(long a,long t) {long ans=1;while(t>0) {if((t&1)==1) ans=ans*a%mod;a=a*a%mod;t>>=1;}return ans;}public static long inv(long x) {return _pow(x,mod-2);}public static void init() {fac[0]=1;for(int i=1;i<maxn;i++) {fac[i]=fac[i-1]*(long)i%mod;}}public static long C(int m,int i) {long ans=0;ans=fac[m]*inv(fac[m-i])%mod*inv(fac[i])%mod;return ans;}public static int gcd(int a,int b) {if(a<b) return gcd(b,a);if(a%b==0) return b;return gcd(b,a%b);}private static MyInputStream cin;public static void main(String[] args) throws IOException{//cin = new MyInputStream();init();Scanner input = new Scanner(System.in);String s=input.nextLine();int len=s.length();int m=input.nextInt();long ans=0;for(int i=len;i<=m;i++) {ans+=C(m,i)*_pow(25,m-i)%mod;ans=ans%mod;}System.out.println(ans);}}


原创粉丝点击