二项式定理+前缀Sigma
Posted --hpy-7m
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二项式定理+前缀Sigma相关的知识,希望对你有一定的参考价值。
https://hihocoder.com/problemset/problem/1430
思路:
要用前缀去推Sigma总公式,比较方便。https://blog.csdn.net/weixin_37517391/article/details/83821752
1 #define ios ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <iostream>//pair 5 #include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin); 6 #include <bitset> 7 //#include <map> 8 //#include<unordered_map> 9 #include <vector> 10 #include <stack> 11 #include <set> 12 #include <string.h>//strstr substr 13 #include <string> 14 #include <time.h>//and(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9; 15 #include <cmath> 16 #include <deque> 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less 18 #include <vector>//emplace_back 19 //#include <math.h> 20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor 21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare) 22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation 23 #define rint register int 24 #define fo(a,b,c) for(rint a=b;a<=c;++a) 25 #define fr(a,b,c) for(rint a=b;a>=c;--a) 26 #define mem(a,b) memset(a,b,sizeof(a)) 27 #define pr printf 28 #define sc scanf 29 #define ls rt<<1 30 #define rs rt<<1|1 31 typedef long long ll; 32 void swapp(int &a,int &b); 33 double fabss(double a); 34 int maxx(int a,int b); 35 int minn(int a,int b); 36 int Del_bit_1(int n); 37 int lowbit(int n); 38 int abss(int a); 39 const double E=2.718281828; 40 const double PI=acos(-1.0); 41 //const ll INF=(1LL<<60); 42 const int inf=(1<<30); 43 const double ESP=1e-9; 44 const int mod=(int)1e9+7; 45 const int N=(int)5e4+10; 46 47 long long C[110][110]; 48 void Init() 49 C[0][0] = 1; 50 for(int i = 1;i <= 100;++i) 51 C[i][0] = 1; 52 for(int j = 1;j <= i;++j) 53 C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod; 54 55 56 57 //======================================================Cnk预处理; 58 ll S[105][N],SS[105][N],ans[N]; 59 char s[N]; 60 61 void solve() 62 63 ll n,k; 64 sc("%lld%lld",&n,&k); 65 sc("%s",s); 66 67 for(int i = 0;i <= n;++i) S[0][i] = 1; 68 for(int i = 1;i <= n;++i) S[1][i] = (s[i-1]-‘0‘) + S[1][i-1] ; 69 for(int i = 2;i <= k;++i) 70 for(int j = 1;j <= n;++j) 71 S[i][j] = S[1][j] * S[i-1][j] % mod; 72 73 SS[0][0] = 1; 74 75 for(int i = 0;i <= k;++i) 76 for(int j = 1;j <= n;++j) 77 SS[i][j] = (SS[i][j-1] + S[i][j])%mod; 78 79 80 for(int i=1;i<=n;++i) 81 82 ll sum=0; 83 for(int j=0;j<=k;++j) 84 85 ll temp=C[k][j]*S[k-j][i]%mod*SS[j][i-1]%mod; 86 if(j&1) 87 sum=(sum-temp+mod)%mod; 88 else 89 sum=(sum+temp)%mod; 90 91 ans[i]=sum; 92 93 for(int i=1;i<=n;++i) 94 pr("%lld%c",ans[i],i==n?‘\n‘:‘ ‘); 95 96 97 int main() 98 99 Init(); 100 int T; 101 sc("%d",&T); 102 while(T--)solve(); 103 return 0; 104 105 106 /**************************************************************************************/ 107 108 int maxx(int a,int b) 109 110 return a>b?a:b; 111 112 113 void swapp(int &a,int &b) 114 115 a^=b^=a^=b; 116 117 118 int lowbit(int n) 119 120 return n&(-n); 121 122 123 int Del_bit_1(int n) 124 125 return n&(n-1); 126 127 128 int abss(int a) 129 130 return a>0?a:-a; 131 132 133 double fabss(double a) 134 135 return a>0?a:-a; 136 137 138 int minn(int a,int b) 139 140 return a<b?a:b; 141
以上是关于二项式定理+前缀Sigma的主要内容,如果未能解决你的问题,请参考以下文章
POJ 3532 Resistance(高斯消元+基尔霍夫定理)