4559: [JLoi2016] Performance comparison time Limit: Sec Memory Limit: + MB
Submit: PNS Solved: 29
[Submit] [Status] [Discuss] Descriptiong Department has a total of n students, M-gate compulsory. The number of these n classmates is 0 to N-1, where B is number No. 0. This m-gate compulsory number is a 0 to M-1 integer. The score that a classmate can get on a compulsory course is 1 to an integer in the UI. If the achievement of a in each course is less than or equal to the result obtained by B, it is said that a is crushed by B. In the case of the B God, the G-system was crushed by him (excluding himself), while the other n-k-1 students were not crushed by him. D God found the B-God's rank for each compulsory course. The ranking here refers to: if the B God a course ranking of R, it means that there are only R-1 students This course score is greater than the score of B God, there are only n-r students this course scores less than equal to B God (not including himself). We need to find out the number of students who are required to score each course, so that they can satisfy both the B-God's claim and the D-found ranking. There are two different cases when and only if any of the students get a different score in any one course. You don't need to be as powerful as D God, you just have to figure out the remainder of the 10^9+7. The first line of input contains three positive integer n,m,k, each representing the number of students in the G series (including B-gods), the number of required courses and the number of students who have been crushed by B-God. The second line contains m positive integers, which in turn represent the highest score UI for each course. The third line contains m positive integers, which in turn represent the rank ri of the B gods in each course. Guaranteed 1≤ri≤n. The data guarantees that at least 1 things make B God's word set. N<=100,m<=100,ui<=10^9output
Only a single positive integer that represents the remainder of the modulo 10^9+7 that satisfies the condition.
Sample Input3 2 1
2 2
1 2Sample OutputTen
principle of tolerance and repulsion + Number of combinations , Good Idea
Wangyuzee is great, Orz.
Overall idea: First to find out all other people and B God each course score relative size of the number of different programs, and then calculate the program number of each course, the product is the answer.
① First part, the direct calculation is more difficult, consider the principle of tolerance.
F[i] Indicates the number of scenarios where I have been crushed, then f[i]=c (n-1,i) *c (n-1-i,rnk[1]-1) *c (n-1-i,rnk[2]-1) *...*c (n-1-i,rnk[m]-1)-f[i+1]*c (i+1,i)-f[i+2 ]*c (i+2,i)-...-f[n-1]*c (n-1,i), that is, the number of at least I-person is crushed by the amount of the program minus the illegal. The inverse recursion of the F array can be obtained.
② The second part is calculated for each door separately and then multiplied.
Assuming that the total score for a course is s,b God's rank and scores are RNK and X respectively, the scheme is x^ (N-RNK) * (s-x) ^ (rnk-1).
Expand ∑c (Rnk-1,i) *s^ (rnk-1-i) *x^ (n-rnk+i), 0≤i≤rnk-1.
We're going to sum up all the things that x=1,2,..., s.
Put together the same number of X-times and convert to 1^p+2^p+...+s^p,p as constant.
Set G[i]=1^i+2^i+...+s^i, then observe the law:
(s+1) ^ (p+1)-s^ (p+1) =c (p+1,0) *s^0+c (p+1,1) *s^1+...+c (p+1,p) *s^p
s^ (p+1)-(s-1) ^ (p+1) =c (p+1,0) * (s-1) ^0+c (p+1,1) * (s-1) ^1+...+c (p+1,p) * (s-1) ^p
......
2^ (p+1) -1^ (p+1) =c (p+1,0) *1^0+c (p+1,1) *1^1+...+c (p+1,p) *1^p
Add the formula: (s+1) ^ (p+1) -1=c (p+1,0) *g[0]+c (p+1,1) *g[1]+...+c (p+1,p) *g[p]
Move Term: g[p]= ((s+1) ^ (p+1) -1-c (p+1,0) *g[0]-c (p+1,1) *g[1]-...-C (p+1,p-1) *g[p-1])/C (P+1,P)
The G array can then be deduced by forward recursion.
In this way, the problem is solved perfectly, time complexity O (n^3).
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long long#define N 105#define mod 1000000007using namespace Std;int n,m,k;ll Ans,s[n],rnk[n],fac[n],inv[n],f[n] , G[n];inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline ll Getpow (ll X,ll y) {ll ret=1;for (; y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;} inline ll C (int x,int y) {return fac[x]*inv[y]%mod*inv[x-y]%mod;} int main () {n=read (); M=read (); K=read (); F (i,1,m) s[i]=read (); F (i,1,m) rnk[i]=read (); fac[0]=inv[0]=1; F (i,1,100) Fac[i]=fac[i-1]*i%mod,inv[i]=getpow (fac[i],mod-2);D(i,n-1,k) {f[i]=c (n-1,i); F (j,1,m) f[i]=f[i]*c (n-1-i,rnk[j]-1)%mod; F (j,i+1,n-1) f[i]= (F[i]-f[j]*c (j,i)%mod+mod)%mod;} Ans=1; F (i,1,m) {g[0]=s[i]; F (j,1,n) {g[j]= (Getpow (s[i]+1,j+1) -1+mod)%mod; F (l,0,j-1) g[j]= (g[j]-c (j+1,l) *g[l]%mod+mod)%mod;g[j]=g[j]*getpow (j+1,mod-2)%mod;} ll Tmp=0,p=1; F (j,0,rnk[i]-1) tmp= (Tmp+c (rnk[i]-1,j) *getpow (s[i],rnk[i]-1-j)%mod*g[n-rnk[i]+j]%mod*p+mod)%mod,p=-p;ans=ans* Tmp%mod;} Cout<<ans*f[k]%mod<<endl;return 0;}
bzoj4559 "JLOI2016" Performance comparison