bzoj4559: [JLoi2016] Performance Comparison

Source: Internet
Author: User

Thanks to grandpa Ding for teaching me the latter part of the problem.

First of all, using the principle of the one-to-one theory, we find out the number of different schemes for each class score relative to B God.

This seems large (wo) (LAN) (Hui) (yi), I will not say, see the code in the F.

Then we need to calculate the number of each individual's score for each course. For each course, we calculate them separately and then multiply them together.

For convenience, the total score is S, ranking is RK.

Set B God's score to X, then the scheme number is x^ (N-RK) * (s-x) ^ (rk-1)

Expand Get C (rk-1,0) *s^ (rk-1) *x^ (N-RK)-C (rk-1,1) *s^ (rk-2) *x^ (n-rk+1) +c (rk-1,2) *s^ (rk-3) *x^ (n-rk+2)-........

Obviously, we need to sum up all the circumstances of X=1..S.

We put together the same number of X-times, and we do a wave of sorting, and the problem turns into a 1^k+2^k+...+s^k.

We set G (k) =1^k+2^k+...+s^k, we list a wave of equations and observe:

(s+1) ^k-s^k=c (k,1) *s^ (k-1) +c (k,2) *s^ (k-2) +...+c (k,k) *s^0

s^k-(s-1) ^k=c (k,1) * (s-1) ^ (k-1) +c (k,2) * (s-1) ^ (k-2) +...+c (k,k) * (s-1) ^0

............................................................................................................

2^k-1^k=c (k,1) *1^ (k-1) +c (k,2) *1^ (k-2) +...+c (k,k) *1^0

Add all these formulas and get:

(s+1) ^k-1=c (k,1) *g (k-1) +c (k,2) *g (k-2) +...+c (k,k) *g (0)

So you can get a recursive way of finding G

And then it's done.

#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib > #include <algorithm> #define LL long long#define N 103#define P 1000000007using namespace Std;inline int Read () {i NT Ret=0;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') Ch=getchar (); while (' 0 ' <=ch&&ch<= ' 9 ') {Ret=ret*10-48+ch;ch=getchar ();} return ret;} int fast_pow (int x,int y) {int ret=1;while (y) {if (y&1) ret= (LL) ret*x%p;x= (LL) x*x%p;y=y>>1;} return ret;} int Bin[n];int fact[n*100];int inv[n*100];int c (int n,int m) {return (LL) fact[n]*inv[m]%p*inv[n-m]%p;} int F[n],g[n];int person,subject,k;int Rank[n],s[n];int Main () {for (int i=fact[0]=1;i<=1e3;++i) fact[i]= (LL) fact[ i-1]*i%p;for (int i=0;i<=1e3;++i) Inv[i]=fast_pow (fact[i],p-2);p erson=read (); Subject=read (); K=read (); for (int i=1;i<=subject;++i) s[i]=read (); int maxrank=0;for (int i=1;i<=subject;++i) Maxrank=max ( Maxrank,rank[i]=read ()); for (int i=person-maxrank;i>=k;--i) {f[i]=c (person-1,i); for (int j=1;j<=subject;++j) f[i]= (LL) f[i]*c (person-1-i,rank[j]-1)%p;for (int j=person-maxrank;j>i;--j) ( f[i]+=p-(LL) f[j]*c (j,i)%P)%=p;} int res=1;for (int i=1;i<=subject;++i) {g[0]=s[i];bin[0]=1;for (int j=1;j<=person;++j) {bin[j]= (LL) bin[j-1]*s[i ]%p;g[j]=fast_pow (s[i]+1,j+1) -1;for (int k=1;k<=j;++k) (g[j]+=p-(LL) C (j+1,k+1) *g[j-k]%p)%=p;g[j]= (LL) g[j]*fast _pow (c (j+1,1), P-2)%P;} int now=0;for (int j=0,k=1;j<rank[i];++j,k=-k) (now+= (LL) k+p) *c (rank[i]-1,j)%p*g[person-rank[i]+j]%p*bin[rank[ i]-j-1]%p)%=p;res= (LL) res*now%p;} printf ("%lld\n", (ll) res*f[k]%p); return 0;}

  

bzoj4559: [JLoi2016] Performance Comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.