容易你全家。。。
只要把每个数能用的求和,再求积即可
用map做。。。做了半天= =
1 /************************************************************** 2 Problem: 2751 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:452 ms 7 Memory:5828 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <map> 12 13 using namespace std; 14 typedef long long ll; 15 typedef pair <int, int> P; 16 typedef map <int, ll> ::iterator IT; 17 const ll mod = 1000000007; 18 int n, m, k, X, Y; 19 ll Sum, ans, del; 20 map <P, bool> GOT; 21 map <int, ll> a; 22 23 inline ll read(){ 24 ll x = 0; 25 char ch = getchar(); 26 while (ch < '0' || ch > '9') 27 ch = getchar(); 28 29 while (ch >= '0' && ch <= '9'){ 30 x = x * 10 + ch - '0'; 31 ch = getchar(); 32 } 33 return x; 34 } 35 36 ll pow(ll x, int y){ 37 ll res = 1; 38 while (y){ 39 if (y & 1) res *= x, res %= mod; 40 x *= x, x %= mod; 41 y >>= 1; 42 } 43 return res; 44 } 45 46 int main(){ 47 n = read(), m = read(), k = read(); 48 P pr; 49 while (k--){ 50 X = read(), Y = read(); 51 pr = make_pair(X, Y); 52 if (!GOT[pr]) 53 GOT[pr] = 1, a[X] += Y; 54 } 55 Sum = (ll) n * (n + 1) / 2 % mod; 56 ans = 1; 57 for (IT i = a.begin(); i != a.end(); ++i){ 58 del = Sum - i -> second; 59 if (del < 0) del += (ll) ((-del / mod) + 1) * mod; 60 ans *= del, ans %= mod; 61 } 62 printf("%lld\n", ans * pow(Sum, m - a.size()) % mod); 63 return 0; 64 }
By Xs酱~ 转载请说明
博客地址:http://www.cnblogs.com/rausen