Bzoj 2751 Easy Questions

Source: Internet
Author: User

Description


In order to make everyone happy, small Q deliberately out of a self-thought simple problem (easy) to meet everyone, this simple question is described as follows:
There is a sequence a known for all A[i] is the natural number of 1~n, and know that for some a[i] can not take what values, we define a sequence of products for the series of all elements of the product, ask you to find out all possible series of product and mod 1000000007 value, is not very simple? Oh!

Input


The first line of three integer n,m,k, respectively, represents the range of values of the sequence elements, the number of sequence elements, and the number of known restricted bars.
Next K-line, two positive integers per line, x, y for a[x] cannot be a value of Y.

Output

An integer on one line represents the product of all possible sequences and the result of modulo 1000000007. If a valid sequence is not, the answer is 0.

Sample Input3 4 5
1 1
1 1
2 2
2 3
4 3
Sample Output90
Sample explanation
A[1] cannot take 1
A[2] can't go to 2, 3
A[4] cannot take 3
So there are 12 possible types of sequences
Series Product
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

Data range

30% of Data n<=4,m<=10,k<=10

There is another 20% of the data k=0

70% of Data n<=1000,m<=1000,k<=1000

100% of Data n<=109,m<=109,k<=105,1<=y<=n,1<=x<=m

Source

It's actually pretty easy. The formula $ans =\prod _ {i = 1}^{i = m} \sum _{j=1}^{j=n}j (J can be filled in I position) $. Because the limit is only K group, up to 100000, so there is no limit to the majority, you can quickly power. There's a limit to violence.

1#include <algorithm>2#include <cstdio>3#include <cstdlib>4 using namespacestd;5 6typedefLong Longll;7 #defineRHL (1000000007)8 #defineMAXN (100010)9 intN,m,k; Pair <int,int>NO[MAXN]; ll RES[MAXN];Ten  OneInlineintQSM (ll A,intb) A { -LL ret =1; -      for(; B;b >>=1, (a *= a)%=RHL)if(B &1) (Ret *= a)%=RHL; the     returnret; - } -  - intMain () + { -Freopen ("2751.in","R", stdin); +Freopen ("2751.out","W", stdout); Ascanf" %d%d%d",&n,&m,&k); at      for(inti =1; I <= k;++i) -     { -         intx, y; scanf"%d%d",&x,&y); -No[i] =Make_pair (x, y); -     } -Sort (no+1, no+k+1); K = Unique (no+1, no+k+1)-no-1; in     inttot =0, last =0; -      for(inti =1; I <= k;++i) to     { +         if(No[i].first = = last) (Res[tot] + = No[i].second)%=RHL; -         Else(Res[++tot] + = no[i].second)%=rhl,last =No[i].first; the     } *ll ans = QSM ((LL) (1+n) * (LL) n>>1)%rhl,m-tot); $      for(inti =1; I <= tot;++i)Panax Notoginseng(Ans *= ((LL) (1+n) * (LL) n>>1)%rhl-res[i]%rhl)%=RHL; -printf"%lld", (ANS+RHL)%RHL); the fclose (stdin); fclose (stdout); +     return 0; A}
View Code

Bzoj 2751 Easy Questions

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.