//#define NDEBUG #pragma region cp_template #include #include #include #include #include #include namespace n91 { using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template auto md_vec(const usize n, const T& value) { return std::vector(n, value); } template auto md_vec(const usize n, Args... args) { return std::vector(n, md_vec(args...)); } template constexpr T difference(const T& a, const T& b) noexcept { return a < b ? b - a : a - b; } template void chmin(T& a, const T& b) noexcept { if (b < a) a = b; } template void chmax(T& a, const T& b) noexcept { if (a < b) a = b; } template class rec_lambda { F f; public: rec_lambda(F&& f) : f(std::move(f)) {} template auto operator()(Args&&... args) const { return f(*this, std::forward(args)...); } }; template auto make_rec(F&& f) { return rec_lambda(std::move(f)); } template T scan() { T ret; std::cin >> ret; return ret; } constexpr char eoln = '\n'; template T ceildiv(const T& l, const T& r) { return l / r + (l % r != 0 ? 1 : 0); } } // namespace n91 #pragma endregion cp_template #include template class modint { using u64 = std::uint_fast64_t; public: u64 v; constexpr modint(const u64 x = 0) noexcept : v(x% mod) {} constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint& operator+=(const modint rhs) noexcept { v += rhs.v; if (v >= mod) v -= mod; return *this; } constexpr modint& operator-=(const modint rhs) noexcept { if (v < rhs.v) v += mod; v -= rhs.v; return *this; } constexpr modint& operator*=(const modint rhs) noexcept { v = v * rhs.v % mod; return *this; } constexpr modint& operator/=(modint rhs) noexcept { u64 exp = mod - 2; while (exp != 0) { if (exp % 2 != 0) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } }; #include #include namespace n91 { template > constexpr T power(T base, U exp, const Operate& oper = Operate(), T iden = 1) { while (exp != 0) { if (exp % 2 != 0) { iden = oper(iden, base); } exp /= 2; base = oper(base, base); } return iden; } } // namespace n91 namespace n91 { void main_() { using mint = modint<1000000007>; /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan(); const usize m = scan(); const usize k = scan(); std::vector a(m); std::vector b(m); for (const usize i : rep(0, m)) { std::cin >> a[i] >> b[i]; } std::vector fact(n + 1), ifa(n + 1); fact[0] = 1; for (const usize i : rep(1, n + 1)) { fact[i] = fact[i - 1] * i; } ifa[n] = mint(1) / fact[n]; for (const usize i : revrep(1, n + 1)) { ifa[i - 1] = ifa[i] * i; } mint ans = 0; for (const usize i : rep(0, m)) { std::vector cnt(k + 1, 0); for (const usize j : rep(0, m)) { if (b[j] > b[i]) { cnt[a[j]] += 1; } } auto dp0 = md_vec(n + 1, m, mint(0)); auto nx0 = dp0; auto dp1 = md_vec(n + 1, mint(0)); auto nx1 = dp1; dp0[0][0] = mint(b[i]) * power(mint(1) / mint(k + 1), n) * fact[n]; for (const usize j : rep(0, k + 1)) { { // 品 for (auto& v : dp0) { for (const usize l : revrep(cnt[j], m)) { v[l] = v[l - cnt[j]]; } for (const usize l : rep(0, cnt[j])) { v[l] = 0; } } // 客 for (const usize l : rep(0, n + 1)) { for (const usize o : rep(0, m)) { for (const usize p : rep(0, n + 1)) { if (l + p > n) { break; } if (o < p && a[i] <= j) { nx1[l + p] += dp0[l][o] * ifa[p]; } else { nx0[l + p][o - std::min(o, p)] += dp0[l][o] * ifa[p]; } } } for (const usize p : rep(0, n + 1)) { if (l + p > n) { break; } nx1[l + p] += dp1[l] * ifa[p]; } } } std::swap(dp0, nx0); std::swap(dp1, nx1); for (auto& v : nx0) { std::fill(v.begin(), v.end(), mint(0)); } std::fill(nx1.begin(), nx1.end(), mint(0)); } ans += dp1[n]; } std::cout << ans.v << eoln; } } // namespace n91 int main() { n91::main_(); return 0; }