题目描述:
为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下:
有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值,我们定义一个数列的积为该数列所有元素的乘积,要求你求出所有可能的数列的积的和 mod 1000000007的值,是不是很简单呢?呵呵!
题目分析:
如果 K=0
则
ans=(n∗(n+1)/2)m
a
n
s
=
(
n
∗
(
n
+
1
)
/
2
)
m
考虑 K!=0
对于被限制的位置,我们判一下重,一个位置可能被多个数字限制。
最后被限制的和不被限制的相乘即为所求
题目链接:
Ac 代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
const int mod=1e9+7;
const int maxm=1e6+100;
struct node{
ll id;
ll x;
}a[maxm];
ll n;
ll m,k;
ll c[maxm];
inline bool comp(node x,node y)
{
return x.id==y.id?x.x<y.x:x.id<y.id;
}
inline ll fastpow(ll x,ll y)
{
x%=mod;
ll ans=1;
while(y)
{
if(y&1) ans=(ans*x)%mod;
x=(x*x)%mod;
y/=2;
}
return ans%mod;
}
int main()
{
ll tot=0;
scanf("%lld%lld%lld",&n,&m,&k);
for(int i=1;i<=k;i++) scanf("%lld%lld",&a[i].id,&a[i].x);
std::sort(a+1,a+k+1,comp);
for(int i=1;i<=k;i++)
{
if(a[i].id!=a[i-1].id) c[++tot]=a[i].x;
else if(a[i].x!=a[i-1].x) c[tot]=(c[tot]+a[i].x)%mod;
}
ll xc=(((n)*(n+1))/2)%mod;
ll ans=1;
for(int i=1;i<=tot;i++)
ans=(ans*(xc-c[i])+mod)%mod;
ans=ans*fastpow(xc,m-tot)%mod;
return printf("%lld\n",(ans+mod)%mod)*0;
}