2751: [HAOI2012]容易题(easy)

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 872  Solved: 377
[Submit][Status]

Description

为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下:
有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值,我们定义一个数列的积为该数列所有元素的乘积,要求你求出所有可能的数列的积的和 mod 1000000007的值,是不是很简单呢?呵呵!

Input

第一行三个整数n,m,k分别表示数列元素的取值范围,数列元素个数,以及已知的限制条数。
接下来k行,每行两个正整数x,y表示A[x]的值不能是y。

Output

一行一个整数表示所有可能的数列的积的和对1000000007取模后的结果。如果一个合法的数列都没有,答案输出0。

Sample Input

3 4 5
1 1
1 1
2 2
2 3
4 3

Sample Output

90
样例解释
A[1]不能取1
A[2]不能去2、3
A[4]不能取3
所以可能的数列有以下12种
数列 积
2 1 1 1 2
2 1 1 2 4
2 1 2 1 4
2 1 2 2 8
2 1 3 1 6
2 1 3 2 12
3 1 1 1 3
3 1 1 2 6
3 1 2 1 6
3 1 2 2 12
3 1 3 1 9
3 1 3 2 18

HINT

数据范围

30%的数据n<=4,m<=10,k<=10

另有20%的数据k=0

70%的数据n<=1000,m<=1000,k<=1000

100%的数据 n<=109,m<=109,k<=105,1<=y<=n,1<=x<=m

Source

题解:

一眼题,不解释。。。

不在家,map记不下来。。。

代码:(copy)

 #include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
#define mod 1000000007
#define K 100010
struct lim{
int x,y;
}l[K];
LL n,m,tot,ans=,mul,tomul;
int k,cnt;
inline bool cmp(const lim &a,const lim &b)
{return a.x<b.x||a.x==b.x&&a.y<b.y;}
inline void quickpow(LL &ans,LL a,LL b)
{
LL mult=a;
while (b)
{
if (b&)ans=(ans*mult)%mod;
mult=(mult*mult)%mod;
b>>=;
}
}
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int main()
{
n=read();m=read();k=read();mul=(n*(n+)/)%mod;
LL x,y;
for(int i=;i<=k;i++)
{
l[i].x=read();l[i].y=read();
}
sort(l+,l+k+,cmp);
tot=m;tomul=mul-l[].y;
for (int i=;i<=k;i++)
{
if (l[i].x==l[i-].x)
{
if (l[i].y==l[i-].y)continue;
tomul-=l[i].y;
}else
{
tot--;
if (tomul<)tomul=tomul%mod+mod;
ans=(ans*tomul)%mod;
tomul=mul-l[i].y;
}
}
if (mul!=tomul)
{
tot--;
if (tomul<)tomul=tomul%mod+mod;
ans=(ans*tomul)%mod;
}
quickpow(ans,mul,tot);
printf("%lld",ans);
}
05-11 13:41